good evening. I have the following code:
pattern="[1-7]{1}(?:\.[0-9]{1,2})?"
The idea is that you can only place notes from 1 to 7 and thus 4.5. But with that code I'm allowed 7.5 for example.
How can I do it so that the maximum score is 7.0?
good evening. I have the following code:
pattern="[1-7]{1}(?:\.[0-9]{1,2})?"
The idea is that you can only place notes from 1 to 7 and thus 4.5. But with that code I'm allowed 7.5 for example.
How can I do it so that the maximum score is 7.0?
You would have to add a or, because there is no way that once the 7 validation has passed, go back to see if it is 7 or 6.
([1-6](\.[0-9]{1,2})?)|7(\.00?)?
Assuming that the decimal part of your notes is only one digit you can achieve through the following regular expression:
^([1-6](\.[0-9])?|7(\.0)?)$
This expression matches with numbers from 1 to 6 with optional decimal part and a single digit and with the value "7" or "7.0"
[1-6]
: number from 1 to 6
(\.[0-9])?
optional group, a " .
" followed by a unique number 0-9
7(\.0)?
the value "7" or "7.0"