js 正则去除指定的单词

以企业邮箱为例:@后面不能是qq   126   163  188 gmail   yahoo   sina   hotmail  suhu   sogu  等单词。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function email1(){

            var Rex=/\w[-\w.+]*@(?!qq\b|163\b|126\b|188\b|gmail\b|yahoo\b|sina\b|hotmail\b|suhu\b|sogu\b)([\w][\w]+\.)+[A-Za-z]{2,14}/;
            var email=document.getElementById("email").value;
            var username_err=document.getElementById("err_email");
            if(email==""){
                username_err.innerHTML="邮箱不能为空";
                username_err.style.color="red";
                return false
            }else{
                if(!Rex.test(email)){
                    console.log(email);
                    username_err.innerHTML="邮箱格式不正确";
                    username_err.style.color="red";
                    return false
                }else{
                    console.log(email);
                    username_err.innerHTML="";
                    return true
                }

            }
        }
    </script>
</head>
<body>
<div class="formControls col-xs-4 col-sm-5">
    <input type="text" id="email" placeholder="请输入企业邮箱"  name="email" value="" class="input-text" required oninput="email1()" >
    <span id="err_email"></span>
</div>
</body>
</html>

 

posted @ 2017-08-02 15:53  龍清扬  阅读(1999)  评论(0编辑  收藏  举报