I want to do a search in a MySQL database for phone numbers.
At present with this query:
SELECT person FROM people WHERE phone_number RLIKE \'1234567
how about:
SELECT
person,
replace(replace(replace(replace(phone_number,' ',''),'(',''),')',''),'-','') as phone_number
FROM
people
WHERE
phone_number RLIKE '^[+]?[-() 0-9]+$';
matches numbers that start with a plus sign, they may contain hyphens, parenthesis and spaces. but no plus signs other than at the start. and also no characters. also removes hyphens, spaces and parenthesis.