Regex don't allow two zeros at the end of a number

I am trying to implement a number input field that will not allow if the number ends with two 0's, i.e. if i enter 23100 then it shouldn't accept it. I am using regex / ^ [0-9] * 00 $ / but this allows 123100.

I pasted code

enter code here

      

+3


source to share


3 answers


you can use

/^(?!\d*00$)\d+$/

      



It will match

  • ^

    - beginning of line
  • (?!\d*00$)

    - negative result, which ensures that no 0 + digits with 00

    endings are allowed
  • \d+

    - one or more digits
  • $

    - end of line
+2


source


Updated now to use backtracks or waits.

^\d*(?:\d?[1-9]|[1-9]\d)$

      



Demo

+1


source


try it. (^\d+[1-9]+0{0,1}$)

This will work for numbers like

12 123 12310 etc.

any number with 2 or more 0 at the end does not match in this case

0


source







All Articles