Regex for "All the digits should not be same for a mobile number"
Solution 1:
You can use this regex to check if all the numbers are the same.
(\d)
is a capturing group, \1
matches against the capturing group {9}
matches \1
9 times, you can edit that figure to suit. So This will tell you if ten numbers are the same.
(\d)\1{9}
JS
text.match(/(\d)\1{9}/g);
http://regexr.com/3efqd
Solution 2:
In your case, the mobile number is of format (9999) 999-9999 Hence , the regex should be
/\((\d)\1{3}\) \1{3}-\1{4}/.test("(9999) 999-9999")
"true"
/\((\d)\1{3}\) \1{3}-\1{4}/.test("(9999) 929-9999")
"false"
here, the split-up explanation of the regex is
\(
-> matches the ( in your string
(\d)
-> matches the first integer and capture it (so that we could backreference it later)
\1
-> picks the first captured element
{3}
-> checks if the capture is repeating 3 times
(space)
-> space
\1{3}
-> checks if the capture is repeating 3 times(backreferencing)
-
-> checks for hiphen
\1{4}
-> checks if the capture is repeating 4 times