手机和邮箱的正则表达式

//正则判断
var phoneReg = /^1[345789]\d{9}$/; 手机号正则格式
var emailReg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/; 邮箱正则格式
phoneReg .test() 判断test()里的手机号值是否为正则
$("#phone").blur(function () {
    if(!$(this).val()){
        phones = false;
        $(this).next().text("*此内容不能为空");
    }else {
        if(phoneReg.test($(this).val())){
            phones = true;
            $(this).next().text("");
        }else {
            phones = false;
            $(this).next().text("*手机号填写有误,请检查");
        }
    }
});

$("#email").blur(function () {
    if(!$(this).val()){
        emails = false;
        $(this).next().text("*此内容不能为空");
    }else {
        if(emailReg.test($(this).val())){
            emails = true;
            $(this).next().text("");
        }else {
            emails = false;
            $(this).next().text("*邮箱格式错误,请检查");
        }
    }
});

猜你喜欢

转载自www.cnblogs.com/jackliu1/p/10281176.html