Live2D

js判断手机邮箱格式(正则)

function fun() {
        var realname = document.getElementById("realname");
        var telephone = document.getElementById("telephone");
        var email = document.getElementById("email");
        // 邮箱格式正则表达式
        var emailPattern =/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
        // 手机号格式正则表达式
        var phonePattern = /^(((13[0-9]{1})|159|153)+\d{8})$/;
        
        if (realname.value == ""){
            alert("姓名不能为空!");
            realname.focus();
            return false;
        }
        if (telephone.value == ""){
            alert("手机不能为空!");
            telephone.focus();
            return false;
        }else if(!phonePattern.test(telephone.value)){
            alert("手机号格式不正确!");
            telephone.focus();
            return false;
        }
        if (email.value == ""){
            alert("邮箱不能为空!");
            email.focus();
            return false;
        }else if(!emailPattern.test(email.value)){
            alert("邮箱格式不正确!");
            email.focus();
            return false;
        }
        return true;
    }

 

posted @ 2019-04-09 15:30  -涂涂-  阅读(898)  评论(0编辑  收藏  举报