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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -