Validation of the telephone number not having all the digits repeated
source link: https://www.codesd.com/item/validation-of-the-telephone-number-not-having-all-the-digits-repeated.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Validation of the telephone number not having all the digits repeated
I want to validate a telephone number of foramt (xxx) xxx-xxxx. This number should not contain all repeating digits. i.e, I have to validate if the user enters a number like (999) 999-9999. But should allow any other format. How to write a regular expression for this.
Please help.
Thanks, Siri
To validate a North American style phone number you could use:
\(?\d{3}\)?[- ]?\d{3}-?\d{4}
This allows the repeating digits. To filter those out, you could run a second regex that uses backreferences to validate all the following digits match the first digit match. Here is a regex with phone formatting optional:
\(?(\d)\1\1\)?[- ]?\1{3}-?\1{4}
Related Articles
Validation of international telephone number
the smallest non-negative number not in a list of repeatable numbers
Navigation, exchange of funds not having all bed; li & gt; on mouseover
Validation of the digital input when formatting the digital input
How to validate the format of the telephone number
Validation of the 7-digit telephone number
The validator of the credit card number does not work properly
Validation of the phone number using JavaScript with .NET?
Validation of the java phone number
What is the point of MVC implementation of IValidatableObject if it can not be used to perform a complete validation of the object?
Validation of the template form does not work and hellip; I do not understand why
Algorithm to find the number of numbers between 2 integers where the digits do not repeat
FindFirstFile / FindNextFile does not return all files in the folder
How do I add values from the text field when I press the button without having all the values
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK