I have a requirement in which we need to restrict the user from entering any of the below value:
000000001 to 000000009 ... 999999990 to 999999999 (unacceptable values) 123123123 (unacceptable value) 123456780 to 123456789 (unacceptable value)
I came up with the below regex :
([0-9])\1{7}([0-9]){1} | 12345678([0-9]){1} | (123){3,9}
This regex can validate if the user has entered incorrect value.
But I am not able to negate the regex. I tried using (?! ) but still it is not performing the negation.
Any help?
21 Answer
Use:
^(?!(\d)\1{7}\d|12345678\d|(?:123){3})\d{9}$ 2