I'm a newbie in java regex. i am seeking for advise for this series of number checking :
Number, must be >= 10 digits, user is not allowed to input as follows:
"0000000000","1111111111","2222222222","3333333333","4444444444",
"5555555555","6666666666","7777777777","8888888888","9999999999",
"1234567890","00000000000","11111111111","22222222222","33333333333",
"44444444444","55555555555","66666666666","77777777777","88888888888",
"99999999999"
currently my regex pattern is something like this
^(?=\\d{8,11}$)(?:(.)\\1*)$
this validates all numbers in the series except the 1234567890. any advise is appreciated. Thank you.
Use this:
^(?!(\d)\1+\b|1234567890)\d{10,}$
See what matches and fails in the Regex Demo.
To validate in Java, with matches we don't need the anchors:
if (subjectString.matches("(?!(\\d)\\1+\\b|1234567890)\\d{10,}")) {
// It matched!
}
else { // nah, it didn't match...
}
Explanation
(?!(\d)\1+\b|1234567890) asserts that what follows is not...(\d)\1+\b one digit (captured to Group 1), follows by repetitions of what was matched by Group 1, then a word boundary|1234567890\d{10,} matches ten or more digitsIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With