Remove special characters
Closed this issue · 3 comments
Hi, first of all, thank you very much for the package, it's amazing and it helps me A LOT!
I needed to do a search by phone number, you know, there are people who put the country code, there are people who don't, there are people who wear masks and there are people who don't, just to exemplify:
(17) 99206-1566
(17) 992061566
17992061566
+55(17) 99206-1566
+5517992061566
.... this is the same phone.
Is there any way when searching for a phone it will search in every possible way?
Hey @capoia
Excited to learn that this is helpful for you.
Actually had something similar to this on the road map.
Will ping you when I have something
Hey @capoia
Been a long time coming but there's now a way to change the search values before searching the DB - see here
For example in your case you can do:
export class User extends BaseModel {
@column()
public name: string
@column()
public phone: string
public static search = search(this, ['name', 'phone'], {
phone: (search: string) => search.replace(')', '').replace('(', ''),
})
}
This way you can remove the special characters before searching the phone column. My example here is super primitive but you can use a regex to properly remove all special characters before searching.
Hope this helps.
Closing since no activity