js正则表达式

//数字验证

jQuery.validator.addMethod("isNum", function(value, element) {   
    var tel = /^([1-9]\d*(\.\d+)?)|(\d+(\.\d+))$/;
    return this.optional(element) || (tel.test(value));
}, "请输入正确的数字");

 

//邮箱验证

jQuery.validator.addMethod("isNum", function(value, element) {   
    var tel = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    return this.optional(element) || (tel.test(value));
}, "请输入正确的邮箱");

 

//身份证验证

jQuery.validator.addMethod("mobile", function (value, element) {
    var length = value.length;
    var mobile = \d{15}|\d{17}[0-9Xx];
    return this.optional(element) || (length == 11 && mobile.test(value));
}, "身份证错误");

 

// 手机号码验证
jQuery.validator.addMethod("mobile", function (value, element) {
    var length = value.length;
    var mobile = /^(((1[0-9][0-9]{1})|(1[0-9][0-9]{1}))+\d{8})$/
    return this.optional(element) || (length == 11 && mobile.test(value));
}, "手机号码格式错误");


// QQ号码验证
jQuery.validator.addMethod("qq", function (value, element) {
    var tel = /^[1-9]\d{4,11}$/;
    return this.optional(element) || (tel.test(value));
}, "qq号码格式错误");

 

// 匹配ip
jQuery.validator.addMethod("qq", function (value, element) {
    var tel = (\d+)\.(\d+)\.(\d+)\.(\d+);
    return this.optional(element) || (tel.test(value));
}, "ip格式错误");

 

// 匹配中文
jQuery.validator.addMethod("qq", function (value, element) {
    var tel = [\u4e00-\u9fa5];
    return this.optional(element) || (tel.test(value));
}, "中文格式错误");

 

// 匹配邮政编码
jQuery.validator.addMethod("qq", function (value, element) {
    var tel =/^[0-9]{6}$/;
    return this.optional(element) || (tel.test(value));
}, "邮政编码格式错误");

 

//验证URL

jQuery.validator.addMethod("qq", function (value, element) {
    var tel =^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$ ;^[a-zA-z]+://(w+(-w+)*)(.(w+(-w+)*))*(?S*)?$;
    return this.optional(element) || (tel.test(value));
}, "URL格式错误");

 

//验证电话号码

jQuery.validator.addMethod("qq", function (value, element) {
    var tel =^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$;
    return this.optional(element) || (tel.test(value));
}, "电话号码格式错误");

 

posted @ 2015-03-23 15:00  streamice  阅读(215)  评论(0编辑  收藏  举报