How to negate the regex in HTML page?

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?

2

1 Answer

Use:

^(?!(\d)\1{7}\d|12345678\d|(?:123){3})\d{9}$

Demo & explanation

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like