Accept all numbers except 5 consecutive zeros : Javascript

前端 未结 4 612
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 17:54

I want to validate a 5 digit number which should not be 00000. All numbers except 00000 are allowed.

examples : 01201 , 00001, 21436 , 45645 are valid numbers and 1,

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-06 18:49

    You can use a negative look ahead:

    ^(?!0{5})\d{5}$
    

    The negative loo ahead (?!...) will fail the whole regex if what's inside it matches, \d is a shortcut for [0-9].

提交回复
热议问题