10 digit mobile number validation pattern in javascript 1

10 digit mobile number validation pattern in javascript

\(?\d+\)?[-.\s]?\d+[-.\s]?\d+

Here is what the above code is Doing:
1. The first part of the regex, ^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$, is called the pattern.
2. The pattern is then compiled into a Regex object.
3. The Regex object is then used to search the string for a match.
4. The search method returns a Match object.
5. The Match object has a group() method that returns the actual matched text from the searched string.

Similar Posts