Validate Phone Numbers with Consecutive Digits in JavaScript
The original regular expression provided aims to validate phone numbers in two specific formats: (123) 456-7890 and 123-456-7890. However, the client now requires an additional validation method for phone numbers with consecutive digits, such as 1234567890.
To accommodate this new requirement, we can extend the regular expression to include the desired format:
/^(?:\+?[\d]{1,3}\W?)?(?:[(]\d{3}[)]|\d{3})?(?:-|\s)?(?:\d{3}-|\d{3}\s)?\d{4,6}$/im
Breakdown of the Regex:
Example Valid Phone Numbers:
The above is the detailed content of How Can I Validate Phone Numbers with Consecutive Digits Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!