I have this simple html:
<input type="text"
placeholder="onlynumbers"
name="onlynumbers"
pattern="\d{1,5}"
maxlength="5">
I need to restrict the number of characters to 5. It works. But I still can type other characters than numbers. I have tried various pattern, for example:
pattern = "[0-9]"
But it is still possible to type other characters than digits.
If I change the type
attribute to number
, then only digits are accepted in the input field but the maxlength
attribute doesn't work. I can enter as many digits as I want. I heard this was a bug in Chrome. Is that the problem?
Is there a cross-browser way to fulfil these requirements:
An input field (text or number, no matters) that only accept digits and doesn't let the user enter more than 5 digits.