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 to accept decimals and whole numbers

As a requirement i need to accept the digits from 0-99 and also the decimal numbers which has 2 digits before (dot) and 14 digits after (dot). Could some one please help me with the regex for this.

examples:

Accepted :

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

1

12

0

99

1.0

11.0

99.0

99.99999999999999 –> upto (2,14 digits)with dot

Not accepted:

123

100

123.1

  1. —> (should be rejected without any digit after decimal)

1.123456789012345 (2,15 digits should not be accepted.)

>Solution :

^\d{1,2}(\.\d{1,14})?$

First Matches 1 or 2 digits, then an optional . plus 1 to 14 digits before line end.

See the results here: https://regex101.com/r/ZTWAXh/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