Searching phone numbers


I’m wondering if there are some best practices around searching through data that can be represented in various ways, in my case phone numbers. Specifically, the international indicator might be included in various ways (eg “0033” or “+33”), might be omitted, and spaces can be included or not.

I’m hesitating between storing the number in one format and doing some string manipulation on the query - at the risk of manipulating some word that was intended for another attribute - or storing all necessary representations of the number.

I see that spaces matching work only if there are no typos, which means the user has to type in all the number before seeing results if i don’t store spaces. Which leads me to think i need to store the numbers both with and without spaces. But if i do so, i have the feeling i would loose the highlightResults feature, as it might jump between one representation and another, which can be awkward.

Many thanks for your help!

1 Like

Hi @paul,
I’ve made some tests and the best way seems to be to

  1. store the number plus its alternative versions without spaces, like 0627316280, +33627316280 0033627316280
  2. remove all the white spaces before sending the search query.

Overview of the my tests:

Let me know how does that go for you.

Hi @alex,

Many thanks for your answer and sorry for the late reply!
Yes, that’ll perfectly work for me.
My concern would be that if i replace a pattern like \d\s*\d, i might in fact corrupt words that were intended for a different attribute than the phone number. But it’s true that in my case, this pattern is unlikely to appear elsewhere (e.g. user names).

Many thanks!