0

I have a scenario where I need to validate a number that is less than 6000.00 It should accept; 0.0, 001.00, 01 , 5999.99, 6000.00 All these should match. 6000.01 should not match.

Anirudh Agarwal
  • 615
  • 2
  • 7
  • 23
  • Do you really want to support zeroes before the whole number like this `001.00`? I don't think you should. In case you really want to support, then are `0000001.00` and `00000021` and similar numbers valid too? And do you want to support numbers without whole number being present? Like `.1` or `.01` too? – Pushpesh Kumar Rajwanshi Feb 16 '19 at 16:54
  • Thats the requirement sir. 0001.00 is valid, before decimal number there can be number ranging from 1 to 4 – Anirudh Agarwal Feb 16 '19 at 17:06
  • Ok Anirudh, if that's the requirement then that's fine. You can use this regex `^0*(?:(?:(?:[0-5]\d{3}|\d{0,3})(?:\.\d{1,2})?)|6000(?:\.0{1,2})?)$`. Check this [Demo](https://regex101.com/r/Falkv4/1/) Let me know if this covers all cases for you. – Pushpesh Kumar Rajwanshi Feb 16 '19 at 17:12

0 Answers0