searching phone numbers mysql
i have list full arbitrarily formatted phone numbers, this
027 123 5644
021 393-5593
(07) 123 456
042123456
i need hunt phone array further erratic format ( e.g. 07123456
should opening (07) 123 456
the proceed i'd normal programming libel frame non-digit characters out 'needle', following by any array haystack, frame non-digit characters out it, following review opposing needle, eg (in ruby)
digits_only = lambda{ |n| n.gsub /[^\d]/, '' }
needle = digits_only[input_phone_number]
haystack.map(&digits_only).include?(needle)
the locate is, i need mysql. horde twine functions, zero unequivocally seem i want.
currently i cruise 2 'solutions'
- hack together franken-query
concat
substr
- insert
%
between each impression needle ( it's this:%0%7%1%2%3%4%5%6%
)
however, conjunction seem quite glorious solutions.
hopefully someone assistance i competence forced %%%%%% solution
update: handling over comparatively bound set data, maybe few hundred rows. i only didn't wish something ridiculously bad destiny programmers cry over.
if dataset grows i'll take 'phonestripped' approach. interjection feedback!
could "replace" duty frame out any instances "(", "-" " ",
i'm concerned outcome being numeric.
the sure characters i need cruise +
, -
, (
, )
space
so fortitude feeling this?
select *
where
replace(replace(replace(replace(replace(phonenumber, '('),')'),'-'),' '),'+')
like '123456'
wouldn't terribly slow?
Comments
Post a Comment