-1

I have some issue in user Authenticate System for example there are tow country called X and Y this two country phone code is +9 and +10 (this is only for example) . this two country have two people name called R and M. R person mobile is +9123456789 and M person mobile number is +10123456789.

There are site called P and this two user come to register on that site and enter the mobile number. both people enter the mobile number without country code but this site get user country code via ip address.

But problem is if we save mobile number as what user enter mobile number field will be duplicate. and if save with country code user don't know about it and next time once he came and enter the same mobile number he entered before system will say invalid mobile number.

i would like to know best way bypass this method . most of websites have this issue.

Thanks

1 Answers1

0

Could you just add a validation for the phone number which requires the country code to be included? (Using either a simple validation for length for a regex). Another option could be using a two columns primary key (ID + phone number).

Also, you didn't specify which language and framework you're using, so it's difficult to give you a code example.

Viktor
  • 2,623
  • 3
  • 19
  • 28
  • Hello VIktor, Thank you for commenting. My issue will come every language in this world. this issue come because duplicate mobile number in this world. if two country people have same number then this problem will be come because most of people enter the mobile number with outout country code so we cant save mobile number with country code one field. i hope you understand my question. thanks – Lakshitha Kumara May 27 '18 at 11:43
  • I think we're having a language barrier here :) What I'm trying to tell is, there are no 2 identical phone numbers, they just have identical parts. When you look at the phone number +123(444 - 555 - 7777 - 66) instead of asking the user for just the (444..66) part, require a full phone number including the country code + 123 ( 44 . 66) that way everyone phone number will be unique. Is this better ? – Viktor May 27 '18 at 12:31
  • This is how i getting mobile number. [1]: https://i.stack.imgur.com/hLDmW.jpg User can enter mobile number or email address.thank your for your suggestion. in your suggection next time when they want login they have to enter mobile number with country code right? Thanks – Lakshitha Kumara May 27 '18 at 13:14
  • Exactly, here's how to do that in Rails https://stackoverflow.com/questions/50544860/how-to-limit-character-word-count-on-database-string-value-in-sinatra-active-rec/50545668#50545668 , instead of maximum you need a minimum attribute. Or if you want to make it easier for your users, you can keep the partial number as a valid input and add a dropdown in your html and get their country code that way. Here's an example: https://gist.github.com/andyj/7108917 Honestly, the number of different ways you could implement this is huge, just pick what suits you the best while making it secure. – Viktor May 27 '18 at 13:23