Answer the question
In order to leave comments, you need to log in
Phone as a login - how to solve?
I decided to do without extra fields and use as a login - a phone number, tk. it is required.
And it is logical: there is no extra field, the login itself does not glow anywhere, the user knows it for sure and only the password will be remembered, the mail to require is such a thing (take, for example, a pizza delivery site - who wants to fill in an e-mail when he wants to eat? My situation is approximately similar - the resource does not fail in life, flood / spam / mailing lists will not be sent, the user will not use the resource often - a couple of times a month, with all this a personal account is needed)
But the problem is how to work with this login-phone?
They paint it all differently, respectively, limit the input, put masks - stupidly.
There is an option for processing the number in js / php, so that only numbers are pushed into the database at once, and during registration, the number is also unified, but there is a problem in +7/8 (and other such cases in other countries). Those. the number processing logic is thickened and you can skip something somewhere for any country.
If you leave it as it is, a user has registered under 89210754591, and is trying to log in under +7 (921) 0754591.
I tend to the second option, because. it is user oriented. But how to handle all these different numbers, with different numbers of digits, different beginnings, etc.
If the guy is from the Russian Federation, then you can count the number of characters, the first digit, and on a couple of conditions already issue a unified login.
What if from another country? How much logic will have to be described and how much to study - cake!
Answer the question
In order to leave comments, you need to log in
The user must indicate the phone number in the international format, you just need to remove all unnecessary characters during registration / authorization, and you can check the phone like this (all countries):
function phone_number($phone)
{
return (bool)preg_match("/^\+?([87](?!95[4-79]|99[08]|907|94[^0]|336|986)([348]\d|9[0-6789]|7[0247])\d{8}|[1246]\d{9,13}|68\d{7}|5[1-46-9]\d{8,12}|55[1-9]\d{9}|55[12]19\d{8}|500[56]\d{4}|5016\d{6}|5068\d{7}|502[45]\d{7}|5037\d{7}|50[4567]\d{8}|50855\d{4}|509[34]\d{7}|376\d{6}|855\d{8}|856\d{10}|85[0-4789]\d{8,10}|8[68]\d{10,11}|8[14]\d{10}|82\d{9,10}|852\d{8}|90\d{10}|96(0[79]|17[01]|13)\d{6}|96[23]\d{9}|964\d{10}|96(5[69]|89)\d{7}|96(65|77)\d{8}|92[023]\d{9}|91[1879]\d{9}|9[34]7\d{8}|959\d{7}|989\d{9}|97\d{8,12}|99[^4568]\d{7,11}|994\d{9}|9955\d{8}|996[57]\d{8}|9989\d{8}|380[3-79]\d{8}|381\d{9}|385\d{8,9}|375[234]\d{8}|372\d{7,8}|37[0-4]\d{8}|37[6-9]\d{7,11}|30[69]\d{9}|34[67]\d{8}|3[12359]\d{8,12}|36\d{9}|38[1679]\d{8}|382\d{8,9}|46719\d{10})$/", $phone);
}
If this is not a bank, but a pizza delivery, then allow these spaces, dashes, brackets, whatever. But keep only the numbers.
When comparing, check the options with and without a country code, you never know how the user entered.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question