2016-01-25 59 views

回答

0

使用maxlength屬性:

<input type = "number" name = "employee_id" size = "20" maxlength= "4"> 
1

最簡單的方法是使用一個jQuery插件,像一個在http://jqueryvalidation.org/

既然你想限制只有4位數它會是這樣的:

$("#myform").validate({ 
    rules: { 
    field: { 
    required: true, 
    digits: true, 
    maxlength: 4 
    } 
} 

});

2
<tr> 
<td>4 digit Employee ID:</td> 
<td><input type = "text" name = "employee_id" pattern="[0-9]{4}" title="4 digit number: e.g. 1234" required></td> 
</tr> 
相關問題