Reputation: 1263
I am trying to write a regex
to use in an <input>
field, where numbers from 0 to 60 are accepted. This is the one I have now:
<input type="number" min="0" max="60" pattern="^([0-5]?[0-9]|60)$">
It works fine, but the issue is that inputs like 02
should not be validated. Do you know how to improve this expression?
Thanks in advance for your replies!
Upvotes: 2
Views: 937
Reputation: 256
<input type="text" min="0" max="60" pattern="^([1-5]?[0-9]|60)$">
Please note that this will also accept "0". Is that desired behavior?
Upvotes: 2
Reputation: 6381
if you don't want to accept 02
, why you put such rule in your pattern?
correct one is: ^([1-5]?[0-9]|60)$
also, as mentioned above in comments, pattern
attribute doesn't work with type=number
- use text
instead (supported are: text, date, search, url, tel, email and password)
Upvotes: 5