0

On my website, people can register with their telephone number. Only one account per phone number is allowed. The problem is: a phone number can be written in several ways.

I'm from Belgium. Our (mobile) phone numbers are like this: 04xx xx xx xx (for example 04 99 12 34 56). Belgium's country code is 0032, so 0032499 12 34 56 is also a valid phone number, just like +32499 12 34 56 is.

So no I have three phone numbers which are exactly the same, but are written different and the system does not recognize them as the same.

Possible solution (will not work)

Every Belgian phone number has the same ending:

00324xxxxxxxx

+324xxxxxxxx

04xxxxxxxx

I could check the last 9 digits (starting with 4), but the problem is: not only people from Belgium can register, also other countries can register. A US mobile phone number does not end with 4xxxxxxxx, so I could not do this check on these numbers.

Possible solution

Adding a dropdown with all the country codes, and normalizing every phone number before it is submitted.

For Belgian phone numbers: +32 (dropdown) 0499 12 34 56 (input) would become +32 (dropdown) 499 12 34 56 (strip the 0).

Possible solution 2

I could use an API like this one (https://www.searchbug.com/api/identify-phone-number.aspx) but it's not free. Is there a free solution I can host myself?

Sam Leurs
  • 1,592
  • 1
  • 19
  • 48
  • If you want to use a pattern, perhaps this page could get you started https://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation – The fourth bird Feb 05 '20 at 08:46
  • Some comment I saved for a question like this: *use [intl-tel-input](https://github.com/jackocnr/intl-tel-input) on frontend and [libphonenumber-for-php](https://github.com/giggsey/libphonenumber-for-php) on backend if you need to sanitize and validate international phone numbers.* – Wiktor Stribiżew Feb 05 '20 at 08:47
  • In which language are you programming your website? – Pierre François Feb 05 '20 at 10:24
  • @PierreFrançois backend is nodejs – Sam Leurs Feb 05 '20 at 11:24

1 Answers1

1

Supposing your website is implemented in PHP, you can normalize your phone numbers before inserting these in your database in the following way:

<?php
$input_number="00324xxxxxxxx";
// or v.gr. $input_number="04xxxxxxxx";
$number=$input_number;

$number=preg_replace("/^00/", "+", $number);
$number=preg_replace("/^0/", "+32", $number); // see remark below

echo "input: ", $input_number, ", normalized form: ", $number, "\n";

If the numbers in the format 04xxxxxxxx are not supposed to be only Belgian numbers, add a drop down feature to force your users to provide a country prefix.

Pierre François
  • 5,850
  • 1
  • 17
  • 38