Finding a Phone Number from MYSQL DB

I have a table with a column phone. The phones in it look like this: +1 (123) 456-3780. If the user enters "35" in the search field, I must show him all the users with the phones:

+3 (534) 000-1010

+1 (350) 000-9090

+1 (003) 534-2343

+1 (001) 223-5323 etc.

I tried to do something like this

SELECT * FROM `mytable` WHERE `phone` LIKE '%3%5'

but this is not the best solution, beacause the request to get other phones, such as +3 (000) 000-500.

I would like to use RLIKE or something like that, but don't know how to create a regular expression and how it should look like?

+2
source share
2 answers

Each input character requires [() -]*:

SELECT * FROM `mytable`
WHERE `phone` REGEXP '3[() -]*5'

This allows you to mark punctuation marks inside your digits "string", but nothing more.

+2

REGEXP '^(.{2})+(\.{4}[-].{4})$' ()

: (00)0000-0000

-1

All Articles