I made a table where input is integer, but somehow I am still able to pass any text.
<tr>
<td>number: </td>
<td><input type="integer" name="number" value=""/></td>
</tr>
is the type="integer" correct?
I made a table where input is integer, but somehow I am still able to pass any text.
<tr>
<td>number: </td>
<td><input type="integer" name="number" value=""/></td>
</tr>
is the type="integer" correct?
In short, integer
is not the correct type - what you seek is number
<input type='number' />
Additional attributes for this type of input are possible, including:
min
: the lowest value the input will allowmax
: the highest value the input will allowstep
: the incremental value that the up/down selectors will increment the current value byFor numeric, you should use type="number"
.
For detailed, you can follow the reference .
Your updated code is given as-
<tr>
<td>number: </td>
<td><input type="number" name="number" value=""/></td>
</tr>
Other Solution: you can do it using JavaScript
validation as given below.
function isNumber(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}
<input type="text" value="" name="number" onkeypress="return isNumber(event)" />