Skip to content
Advertisement

Allow only numbers with only specific alphabets in textbox

i have a text box in html, i want to allow user to only input following range

0-9 and NA

there are two cases
1: user inputs range form 0-9 numbers and
2: user inputs only NA (NA denotes Not applicable)

how could i allow user to do this

I try following code but it does not work

<input type = "number" autocomplete="off" class = "form-control"  name="Personal_Weapons_Price" id = "Personal_Weapons_Price"   required  onkeyup="this.value = this.value.toUpperCase();" pattern="[^0-9NA]+" />

Advertisement

Answer

Add This Way oninput="this.value = this.value.toUpperCase().replace(/[^NA0-9]/, '')"

<input type="text" oninput="this.value = this.value.toUpperCase().replace(/[^NA0-9]/, '')" />
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement