Accept only specific numbers in an input
-
I have the following input:
Conta Despesa: <input type="number" name="cod_reduzido">
However, it should accept only specific numbers (there are 30 numbers that are not in sequence, such as: 3111, 3113, 3130, etc.)
-
It doesn't make sense for your input type to be number(with arrow behavior to increment and decrease, and you're not using sequence. So I switched to
type="text"
but I added a parameter calledpattern
that validates your input through a https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/RegExp .As your case is specific with numbers without some logic between you will need to write the RegExpna nail yourself! Follow example with the 3 numbers you have passed, just add the remaining separated by
|
(OR).Conta Despesa: <input type="text" name="cod_reduzido" pattern="3111|3113|3130"> <input type="submit" value="validar">