文本框jquery前端验证
jQuery.validator.addMethod("loginname", function(value, element) {
var tel = /^[a-zA-Z][a-zA-Z0-9_]{4,16}$/;
return this.optional(element) || (tel.test(value));
}, "");
jQuery.validator.addMethod("phonenumber", function(value, element) {
var tel = /^(13[0-9]|15[0|3|6|7|8|9]|18[3|6|7|8|9])\d{8}$/;
return this.optional(element) || (tel.test(value));
}, "");
jQuery.validator.addMethod("income",function(value,element) {
var val = /^\+?[1-9][0-9]*$/;
return this.optional(element) || (val.test(value));
},"");
//上面都是为下面设置正则表达式格式
$(function() {
$("#clear").click(function() {
$(".inputbox").val("");//点击清空,清空所有文本框
});
var addForm = $("#addCustomerForm").validate( {
rules : {
customerName : { //文本框ID
required : true
},
customerTel : {
phonenumber : true
},
customerAddr : {
required : true
},
customerBirthday : {
required : true
},
customerIscome : {
required : true,
income : true
},
customerCharacter : {
required :true
},
birthdayDate :{
required : true
}
},
messages : {
customerName : { //文本框ID
required : ""
},
customerTel : {
phonenumber : ""
},
customerAddr : {
required : ""
},
customerBirthday : {
required : ""
},
customerIscome : {
required : "",
income : ""
},
customerCharacter : {
required : ""
},
birthdayDate : {
required : ""
},
focusInvalid : false,
onkeyup : false
//获得焦点时不验证
}
});
jquery表单验证插件------>附件