//jquery validate扩展var reg_cn = /^[\u0391-\uFFE5]+$/;var reg_user = /^\w+$/;var reg_phone = /^\d{3,4}-?\d{7,8}$/;var reg_email = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;var reg_url = /^(http:\/\/)?[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;var letter_number = /^[A-Za-z0-9]+$/;var reg_time = /^\d{2}\:\d{2}$/;if($.validator){ $.validator.addMethod("userName", function (value, element, param) { if(reg_cn.test(value)){ if(value.length < 2 || value.length > 10){ return false; }else{ return true; } }else if(reg_user.test(value)){ if(value.length < 4 || value.length > 20){ return false; }else{ return true; } }else{ return false; } },"4-20位字符 <字母,数字,下划线> ,或者2-10个中文!"); $.validator.addMethod("realName", function (value, element, param) { if(reg_cn.test(value)){ if(value.length < 1 || value.length > 10){ return false; }else{ return true; } }else if(reg_user.test(value)){ if(value.length < 2 || value.length > 20){ return false; }else{ return true; } }else{ return false; } },"2-20位字符 <字母,数字,下划线> ,或者1-10个中文!"); $.validator.addMethod("postcode", function(value, element) { var tel = /^[0-9]{6}$/; return this.optional(element) || (tel.test(value)); }, "请输入正确的邮政编码!"); $.validator.addMethod("phone", function(value, element) { var tel = /^\d{7,8}$/; //电话号码格式010-12345678 return this.optional(element) || (tel.test(value)); }, "请正确填写您的电话号码"); $.validator.addMethod("email", function(value, element) { return reg_email.test(value); }, "邮箱格式不正确!"); $.validator.addMethod("mobile", function(value, element) { return this.optional && this.optional(element) || /^1\d{10}$/.test(value); }, "手机号码格式不正确!"); $.validator.addMethod("url", function(value, element) { return reg_url.test(value); }, "网站格式不正确!"); $.validator.addMethod("cnName", function(value, element) { return reg_cn.test(value) && value.length > 1; }, "中文名格式不正确!"); $.validator.addMethod("englishName", function(value, element) { return /^\w+[\w\s]+\w+$/.test(value) && value.length >= 4 && value.length <= 20; }, "英文名格式为4-20位字母!"); $.validator.addMethod("decimal", function(value, element) { return /^\d+(\.\d{0,2})?$/.test(value) && value > 0; }, "必须是大于0的数!"); $.validator.addMethod("letter_number", function(value, element) { return letter_number.test(value); }, "必须是英文或数字"); $.validator.addMethod("time", function(value, element) { return reg_time.test(value); }, "时间格式为10:00");} 字母,数字,下划线> 字母,数字,下划线>