S
S
slava kk2019-03-15 21:14:16
PHP
slava kk, 2019-03-15 21:14:16

How to check the validity of the number in php?

The number from the user is received in the format 7(999)999 99-99, how to filter numbers like:
7(000)000 00-00, 7(777)777 77-77, etc.?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2019-03-15
@Sanasol

You can check only the first couple of digits, everything else can be anything.
https://www.regextester.com/94215
So +79991111111 is a very real number, like +79999999999
The maximum that can be done is to check for the same characters in the number, if at all the entire number consists of one digit, then draw conclusions.
In general, if you really need to validate a number, send an SMS to it or dial it with a random number (although it seems already illegal in the Russian Federation, you can’t replace numbers with any) and ask for numbers.

E
Edward Pashchenko, 2019-05-07
@edwardjeanx

if(count( array_unique( str_split( preg_replace("/[^0-9]/", "", $_POST['tel']) ))) > 4) {
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question