1
I’d like to use one pattern
in my input
(has to be the text
) with the following rules:
- Input only accepts up to 4 characters.
- These characters can only be numbers from 0 to 9.
- User CANNOT start typing 0. Ex:
- 0100, 0001, 0050 (Not allowed)
- 1020, 1000 (May).
I started doing the following code below, but it’s not working very well.
<input class="form-control" type="text" id="cod" name="cod" pattern="[0-9]+$" maxlength="4" placeholder="Digite o código da empresa(Somente números)" required autofocus />
But it didn’t work. (In this case of my code, I couldn’t even stop the field from receiving only numbers).
OBS: I would like to use only the pattern
input, without Javascript or jQuery.
If I want to accept from 1 to 4 characters just take that {3} ? Would you accept the number '999' and not accept '012'? (In case, I wish the user could type "1 to 4" numbers. Not only "4" characters).
– Gato de Schrödinger
@Thiagopetherson updated the answer
– hkotsubo