I have phone number saved for my clients in my database, As you know the phone number has no specfic format, so some numbers are like (+1)123 3123 OR 212-43-1., problem is with in my php code I make a query to check either a phone number exist so If I enter number like 11233123 then it will result no result but it is already there. Any solution on how to match? The solution in my mind is to remove all the special characters while checking

有帮助吗?

解决方案

You can use REPLACE to remove special characters from the data in the database during your query. Or when you add a phone number, in PHP, remove the special characters and save the phone number as just the numbers. Then search against the column that you removed the special characters from.

Here is documentation for REPLACE (it's under strings, don't get confused with the REPLACE query type): http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_replace

As stated by most people posting on this page, cleaning the input before adding it to the database is the preferred method.

其他提示

Phone numbers in database should be for this specific reason normalized.

Or you can take a look at another questions here how to search in chaos.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top