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

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -