Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Regex decimal greater than 0 less than 1 with at most 3 decimal places

I want to make a decimal number that is greater than 0 and less than 1, with at most 3 decimal places. So 0, 0.0004, 0.00, 00.004, are NOT valid. But 0.004 is valid.

I thought this shall be simple but couldn’t get it working.
This is what I came up with: /^0(?:\.)([1-9]{1,3}?$)/g which makes 0.004 invalid but 0.004 is valid.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This regular expression should do the trick

^0\.\d{1,3}$

You can test it here

https://regex101.com/r/IwQsaD/1

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading