Categories: Programming

Search a formatted number in a MySQL table with a differently formatted search word

Here is the MySQL query to find formatted phone number by a differently formatted search text

People enter phone number in various formats on the web.  Some people just write down the number without space or hyphens. Some does with ( brackets etc.

Sometimes we have to store it as it is to keep the clients /user happy. But its pain when you want to verify the number or do a search with number by entering entirely a different format.  Following MySQL query helps you do it with ease.

It strips off all symbols and spaces from the data which is there in entire phone number data in your db and matches it with the query text you enter.

Here is the MySQL query to find formatted phone number by a differently formatted search text.

SELECT * FROM bizz_business_user
WHERE 
TRIM(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(phone,
          ' ',   '' ),
          '-',   '' ),
          ',',   '' ),
          '/',   '' ),
          '(',   '' ),
          ')',   '' ),
          '+46', '0')
        ) = '2403473649'

Hope this helps you to do awesome things with phone numbers.

Remiz

Remixed version of unstable human emotions and thirst of mankind actions. UX designer, UI developer and HE of WebCastle Media Pvt LTD

View Comments

  • this method is indeed slow(not n hour late :P) .Use "SELECT * FROM `table`
    WHERE `numberes` REGEXP '1[() -]*9'" (when you search '19')
    Note You need a [() -]* between each input character.Expected data:+1 (003) 534-2343

Recent Posts

Apple push notification php example code 2021

For a long time since Push notification became a thing on iOS, it was very simple to integrate push notification…

11 months ago

Solved: MySQL convert_tz returns null on MacOS Catalina using XAMPP

Note: A little bit of a story since I haven't been writing for a while. If you are in a…

3 years ago

Why You Should Hire a Creative Marketing Agency for Your Next Campaign

There are few things that are quite as universally important in a business like marketing. Good marketing is at the…

3 years ago

Bring back PPTP VPN on iOS 10 and macOs sierra

Since latest iOS and macOs removed support for PPTP VPN from their built in client, here is how you can…

6 years ago

This will Change

Back to habits of young days. Shaping up another life. Starting like a kid who is a great king.

8 years ago

2013 – the fastest year ever !

Today, when I logged in to my pc & open Chrome, I saw this nice Google Doodle for New Year’s…

8 years ago