mercredi 1 décembre 2021

How to format the search input to us format phone number

as in table the phone numbers are stored in us format as (###)-###-####

and i tried to search it, as im getting the input from user as string(phone number)

and i tried to convert that as

 search_input = search_input.unpack('A3A3A4').join('-').insert(0,'(').insert(4,')')

it works if the complete phone number is typed, but

as if the user input single digit , the query searches like %#--% like this and nothing

gets fetched , so how to modify that command

my query will look like

    result = users.where('users.phone_number_1 ilike :search', {search: "%#{search_input}%"})

or on the above query is there any posiblity to remove the special charcter('(',')','-') while searching?, so that it searches with the phone number alone..

thanks in advance

Aucun commentaire:

Enregistrer un commentaire