Search code examples
regexpcre

regex to catch any currency under $300K


I have a requirement to identify any values under 300,000 in a currency field. I created a regex that will do this for any number under 1 million, but I need to cut it off at $299,999.99.

The code for 1 million is listed below.

^\$?\d{0,3}?\d{0,2},?\d{0,3}(\.(\d{0,2}))?$


Solution

  • You can use the following regular expression: ^\$[0-2]?[0-9]{0,2},?[0-9]{0,3}(\.[0-9]+)?$

    See the explanation on regex101...

    enter image description here

    Here you can visualize your regular expression...