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

A regular expression (regex) for allowing numbers starts from 0 and after point two digit allow

I have regular expressions that allow numbers from 0 to 999999999999999999.99
which is allow

  1. After a point it will only be two-digit (eg. 151531.99)
  2. Allow Integer like 1, 2, 3565, 48784, 87848541, 151515

I have found one regex which is [+]?([0-9]*\.[0-9]+|[0-9])
But it does not look above condition.

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 part |[0-9] is an alternative that matches a single digit.

In this part [0-9]*\.[0-9]+ the digits and to are optional so it can match a leading dot as well.

You can match 1-18 digits and optional dot and 2 digits. Using anchors to prevent a partial match.

^\+?\d{1,18}(?:\.\d{2})?$

Regex demo

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