Reputation:
Values accepted:
6.0
5.9
0.0
1.1
6
5
not accepted:
6.01
6.1
5.99
0.00
what i have tried (1 decimal place) don't know how to limit till 6
^[0-9]+(\.[0-9]{1,1})?$
Upvotes: 1
Views: 181
Reputation: 626960
You may use
^([0-5](?:\.\d)?|6(?:\.0)?)$
See the regex demo
Details:
^
- start of string(
- start of an alternation group:
[0-5](?:\.\d)?
- a digit from 0
to 5
followed with an optional sequence of a .
followed with a single digit|
- or6(?:\.0)?
- 6.0
or 6
)
- group end$
- end of stringUpvotes: 3