0

With reference to my previous question currency regex

I want to add an condition, i want to allow decimal only if it starts with 0

example

0.25 should be allowed 1.25 not allowed

current regex is as following

/^(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?$/ 

which matches comma trailing etc.

Community
  • 1
  • 1
d-man
  • 53,999
  • 81
  • 200
  • 285

1 Answers1

1

This will match all the currency matches from before without decimals or decimals with 0.x*

/^((?:\d{1,3}(?:,\d{3})+|\d+)|(?:0\.\d+))$/

If you only want to match 0.xx instead of an arbitrary number of decimal places use

/^((?:\d{1,3}(?:,\d{3})+|\d+)|(?:0\.\d{2}))$/

This one changes \d+, one or more digits, to \d{2}, exactly 2 digits.

Will Barnwell
  • 3,729
  • 18
  • 33
  • 1
    regex always been pain for me. can you explain the the second regex i appreciate in advance – d-man Dec 13 '16 at 21:15