-1

I was just wondering how people are handling phone number validation. What im doing is; a user enters in mobile-phone(071412345) number and based on the first three digits assigns an international code(+4401412345) to it. But I had to declare a regex for each country, and how can i make this cleaner/better?

The suggested link is not really what im looking for

AndroidAL
  • 1,111
  • 4
  • 15
  • 35
  • i have regex for each country, that contains mobile phone prefixs that can be found in each country. So over 100 regex. – AndroidAL Jul 15 '15 at 15:32
  • i have posted my answer with best of knowledge i have . Thanks & Dont Forget to accept it if it helps you . – Meghal Agrawal Jul 15 '15 at 15:34
  • Thanks, but not really what im looking for. – AndroidAL Jul 15 '15 at 15:36
  • You're trying to determine the country of origin of a phone number based on the first three digits of the domestic number? That is utterly daft. There will be so much overlap that you'll never get it to work. If you could make it work we wouldn't need international prefixes, would we? How are you going to maintain it? Are you prepared to monitor the phone numbering schemes in every country and update your code every time a new range is opened up? –  Jul 15 '15 at 17:22
  • @HoboSapiens, how would you tackle it ? – AndroidAL Jul 21 '15 at 07:51

1 Answers1

-2

The trend running today is two-factor authentication . And the cheapest way i know for that is giving a missed cal to user and automatically detect weather or not the user have got an miss call from the same number .

You can use Sdk's for that .

I have used https://www.cognalys.com/

This site automatically detects country after calling a method something like cognalys.getCountryCode();

It is great for verifying users .

Also you can send otp to your users . You have to follow these steps -

1.Generate a random otp in server side .

  1. Take input from user from mobile application . send that to your server .

3.Then from server send an otp to that number using an sms api provider .

4.Then Take user input otp .

5.Then send that otp from mobile application to server side .

6.Then check if that otp matches your generated one .

If it matches . .User Verified

Hopes this helps you ..

Thanks

  • 1
    Meghal, I guess you got this wrong, OP is asking for **phone number validation** not **phone number authentication** as in OP intended to find the country code based on the number entered. – Sudhansu Choudhary Jul 15 '15 at 15:39
  • Am I making sense in what im asking? – AndroidAL Jul 15 '15 at 15:56
  • @user177931 yes you are! the question does make sense. Although I, as of now can't think of anything except what you already have on hand, I mean the regex thing. You would definitely need to cross check the format of entered number with the available countries code. Have you got a chance to look into html5 tel i/p? Wonder if that can help you. As of now works with some of the browsers only but a shim should be available for the non supporting browsers too. If it helps, that is! – Sudhansu Choudhary Jul 15 '15 at 16:48