Matching phone number from mysql to php

I have a phone number stored for my clients in my database. As you know, the phone number does not have a special format, so some numbers are similar to (+1)123 3123 OR 212-43-1., The problem is in my php code. I am making a request to verify that a phone number exists. If I enter a number like that 11233123, then the result will not have a result, but it already exists. Any decision on how to fit? The solution, in my opinion, is to remove all special characters when checking

+3
source share
2 answers

You can use REPLACEto remove special characters from the data in the database at the time of the query. Or, when you add a phone number, in PHP, delete the special characters and save the phone number as numbers. Then search the column in which you deleted special characters.

Here is the documentation for REPLACE(it’s under the lines, do not confuse with the type of request REPLACE): http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

As stated by most users on this page, clearing the input before adding it to the database is the preferred method.

0
source

Phone numbers in the database must be normalized for this reason .

questions .

0

All Articles