i am creating a web page where I have a input text field in which I want to check only 开发者_如何学运维4 or 16 numeric digit
How can i make it using jquery?
Something along the lines of :
$('#form').submit(function(){
var val = $('#someinput').val();
if(/^(\d{4}|\d{16})$/.test(val) == false) {
// do something
return false;
}
}
);
Use jQuery validator: Source
$("#myform").validate({ rules: {
field: {
required: true,
minlength: 4,
maxLength:16
} } });
if your looking for jquery validation this methode will help you
jquery validation(http://bassistance.de/jquery-plugins/jquery-plugin-validation/)
$.validator.addMethod("textfield", function(value, element) {
return this.optional(element) || /^(\d{4}|\d{16})$/ i.test(value);
}, "<br>You must enter 4 digit or 16-digit");
Please clarify your question !
精彩评论