mandes — 2012-08-05T18:28:58-04:00 — #1
I have a table with 2 fields holding phone numbers 'Home' and 'Mobile' over the years these have been populated with no standardisation on format, so I have
you get the picture
Now I need to be able to search by phone number (or part phone number) so I need to strip out all non numerical characters so I can perform a LIKE with the inputed string. Can I do this on the fly within the query ?
r937 — 2012-08-05T19:17:52-04:00 — #2
use the mysql REPLACE function, nested as many times as necessary
,'+','') LIKE '%937%'
mandes — 2012-08-05T19:38:00-04:00 — #3
Thanks Rudy, was kind of hoping there was a more complete solution like a regex to remove everything but numbers, but thats working OK.
spacephoenix — 2012-08-05T19:40:35-04:00 — #4
I'm not aware of a way. You may want to consider in whatever server-side language is in use for each phone number in turn, explode it into an array (1 character per array element). Then for each element of the array check to see if it's numerical, if it's not remove it from the array, once all elements have been examined, combine them back into a string and update the phone field in the database with the sanitized phone number.
mandes — 2012-08-06T02:16:27-04:00 — #5
SpacePhoenix - yes I was thinking last night that would probably be the way to go, the client still wants to to be able to format the numbers using some symbols, so I'll set a standard and sanitise on input, then write a script to strip these out in php as they are entered to the database, I'll probably create one new field with both numbers stripped and pasted together then use that for my searching.