我想要minlength=8
和maxlength=14
,我该如何实现这个验证。
html:
<input type="text" name="354" id="field">
jQuery:
$("input[name=354]").keypress(function(e){
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
$("#errmsg").html("Digits only").show().fadeOut("slow");
return false;
}
});
最佳答案
现在对于 HTML5,您可以使用属性 minlength
和 maxlength
。
<input type="text" minlength="8" maxlength="14" name="354" id="field">
关于javascript - jquery 最小和最大长度验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37057513/