javascript - Trying to only allow 4 numbers in a field -
i trying make sure validate 4 digits can numbers in field, , letters cannot accepted. field.
<tr> <td id="exam_number">exam number</td> <td><input type="text" name="exam_number" /></td> </tr>
helpful answer here
specifically, you'd want change input element to:
<input type="text" maxlength="4" pattern="[0-9]{4}" title="four digit test number" name="exam_number"/>
and use jquery allow digits shown here
$("#myfield").keyup(function() { $("#myfield").val(this.value.match(/[0-9]*/)); });
Comments
Post a Comment