15,609,601 members
See more:
Can anyone help me with the regular expression for any number from 0 - 10 with maximum of 2 decimal

Valid numbers:
0.23
1.02
6.2
7.20
10.00
10

Invalid numbers:
10.01
12.333
0.233

Posted
Updated 14-Dec-21 22:20pm

## Solution 3

This will work:
`^(10|\d)(\.\d{1,2})?\$`

(10|\d) allows for a single digit or 10
(\.\d{1,2})? possible decimal followed by 1 or 2 digits

## Solution 4

^((10)(\.[0-0]{0,2})?\$|([0-9])(\.[0-9]{1,2})?\$)

the above regex code work for 0.00 to 10.00

^((0)((\.0[1-9]{1})?\$|(\.[1-9][0-9]{0,2})?\$)?\$|(10)(\.[0-0]{0,2})?\$|([1-9])(\.[0-9]{1,2})?\$)
this is for 0.01 to 10.00

v2
Patrice T 15-Dec-21 4:26am
CHill60 15-Dec-21 8:21am
You may not be aware, we have been asked to allow new solutions to old posts (by Chris and Sean) - especially if they add something new, or in this case, are correct when the other two explicit solutions (1 and 3) are not
CHill60 15-Dec-21 8:19am
I have countered the downvote on your solution because, unlike solutions 1 and 3, your first regex handles all of the examples given and rejects the specific invalid numbers listed.
Your second regex is irrelevant and does not match the question requirements

## Solution 1

Try:
`^((1\d)|(\d))(\.(\d\d)|\d){0,1}\$`

Brian A Stephens 20-Sep-13 10:10am
Your regex allows numbers 11-19 also, which shouldn't be included.