Only accept specific numbers in an input

0

I have the following input:

Conta Despesa: 
<input type="number" name="cod_reduzido"> 

But it should accept only specific numbers (there are 30 numbers that are not in sequence, such as: 3111, 3113, 3130, etc.)

    
asked by anonymous 26.12.2017 / 17:39

1 answer

2

It does not make sense for your input type to be number (with the behavior of the arrows to increment and decrement being that you are not using sequence.) So I switched to type="text" , however I added a parameter called pattern that validates the your input through a RegExp .

As your case is specific with numbers without some logic to each other, you will need to write the RegExpna nail itself! Here is an example of the 3 numbers you have just added the rest separated by | (OR).

Conta Despesa: 
<input type="text" name="cod_reduzido" pattern="3111|3113|3130">
<input type="submit" value="validar">
    
26.12.2017 / 17:54