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 0
s:
^(?!.*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
Post a Comment