I am trying to write a regex validator to accept numbers with only the decimal part 0 or 5 and only in the range 0-5. eg:
-1 false
-.5 false
-0 false
000000 true
0.0 true
0000. true
0 true
.50000000 true
00001. true
01.50 true
2.00000 true
2.5000 true
03 true
03.5 true
0004 true
0004.5000 true
00005.0 true
0 true
0.5 true
1 true
1.5 true
2 true
2.5 true
3 true
3.5 true
4 true
4.5 true
5 true
1.05 false
5.5 false
10 false
20 false
30 false
40 false
50 false
No matter how many 0s are in front or behind the digits, it can really be.
I tried this ^[0-5]+(?:\.[05]0?)?$, but it fails in the following cases: 0000., .5, 001.and5.5
Many thanks!
source
share