javascript - Regular expression to not allow 2/3/4 consecutive zeros in string -


i want validate textfield: not want allow below entries in textbox:

100123456- 2 repeating zeros max length 9

120005689- 3 repeating zeros max length 9

100005689- 4 repeating zeros max length 9

i have tried below regex:

/^(?!.*(.)\1)(^[1-9][0-9]{8}$)/ 

it works, not allow repeating other numbers. eg: 114564568- because 1 repeating

i want zeros. if there consecutive zeros show error.

please help.

thanks in advance

you can use following regex disallow 2 consecutive 0s:

^(?!.*00.*)([1-9][0-9]{8})$ 

or more elegant version:

^(?!.*0{2}.*)([1-9][0-9]{8})$ 

any 9-digit number starting digit other 0, , not have 00 pass. actually, if not allow 2 consecutive zeros, won't allow 3 , 4 consecutive zeros @ same time.

see demo.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -