Removing all non-numeric characters from a string

I have a property that I want to keep, but I also need a numeric-only version.
If that makes no sense, I’ll give you context. Let’s say you want to easily search for Phone numbers. People tend to enter their phone number in many ways. Here are some examples

Start with a number that is "025456111".

You could end up with
"025 456 111"
"025 456111"
"025-456-111"
"(025) 456 111"
"025 456 ext 111"

And any combination of that.

So, in your database it might be a good idea would be to have a column on the phone table which holds a clean (i.e. numeric only) version of the phone number.
Then your search module just needs to take the search input, and perform the same clean. That way you have cleaned up the noise and made searching a lot simpler!

Also don’t forget to update existing data.

Subscribe

0 comments