Answer the question
In order to leave comments, you need to log in
How to make a regular expression to validate a number?
Hello.
I have a regular expression like this
/^((8|\+7|7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ] {7,10}$/
It checks the following numbers: 8(XXX)-XXX-YY-YY
How can I make it check landline numbers as well, for example, XX-XX-XX.
Answer the question
In order to leave comments, you need to log in
either check for exact pattern matching with a simple regular expression, or it doesn’t make sense to suffer like this, because the spelling options are 100500: 8(86-141) 3-39-40 , +375 (44) 560-51-74 , so check what remains after removing brackets, spaces and hyphens
You can combine regular expressions for different types of numbers using |.
But here you need to take into account the possible different formats of numbers (there are landline numbers with 7 digits, etc.)
PS When he himself solved the problem of validating phone numbers, as a result, the validation was removed so that the valid number entered by the user does not mean that this number will be a real number and not a random dialing digits.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question