Reputation: 1246
I have a table with phone
column. Phones in it looks like this +1 (123) 456-3780.
If user input in search field "35" i should show him all users with phones:
+3 (534) 000-1010
+1 (350) 000-9090
+1 (003) 534-2343
+1 (001) 223-5323 etc.
i have tried to do something like that
SELECT * FROM `mytable` WHERE `phone` LIKE '%3%5'
but this is not the best solution, beacause query get other phones like that +3 (000) 000-500.
I would like to use RLIKE or something like that, but do not know how create needed regular expression and how should it look?
Upvotes: 2
Views: 2473
Reputation: 1
REGEXP '^(.{2})+(\.{4}[-].{4})$'
this pattern is for phone numbers with ()
example: (00)0000-0000
Upvotes: -1
Reputation: 385174
You need a [() -]*
between each input character:
SELECT * FROM `mytable`
WHERE `phone` REGEXP '3[() -]*5'
This allows punctuation to exist inside your digit "string" but nothing else.
Upvotes: 4