22 May 2018

How can I search for a phone number?

There is no universal way to write phone numbers, and you might have them in several formats in your database (805-555-5555, 8055555555, +18055555555). How should you store them in an Algolia index?

First of all, the dash (-) and plus (+) signs are no issue as the engine treats them as separators. Adding them or not won’t impact the search.

We also suggest that you disable typo-tolerance on this field through the disableTypoToleranceOnAttributes option.

If you’re dealing with international phone numbers, your users might type them in different formats. For example, the number +999 555-254-6542 can also be typed as 05552546542 if called locally, or 5552546542 if no prefix is added. To allow your users to find the correct result no matter how they type their number, we suggest storing the three formats in an array (and adding it to the searchableAttributes). You should also add another field, with the number correctly formatted, to be used when you display the results.

  "phone_numbers": ["9995552546542", "05552546542", "5552546542"],
  "formatted_phone_number: "+999 555-254-6542"