Enhancing JavaScript Phone Number Validation to Handle Consecutive Numbers
The current regular expression, /^(()?d{3}())?(-|s)?d{3}(-|s)d{4}$/, is efficient in validating phone numbers in formats such as (123) 456-7890 or 123-456-7890. However, to accommodate the additional requirement of validating consecutive numbers like 1234567890, a modified regular expression is necessary.
The modified regular expression is as follows:
/^[\+]?[0-9]{0,3}\W?+[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im
Explanation of the Regular Expression:
This regular expression covers all the previously validated formats, as well as the new consecutive number format of 1234567890.
The above is the detailed content of How Can JavaScript Phone Number Validation Be Enhanced to Include Consecutive Number Sequences?. For more information, please follow other related articles on the PHP Chinese website!