js 驗證電子郵箱

js:

<script  type="text/JavaScript">  
   function checkemail()
    {
        var temp = document.getElementById("email");
        var myreg = /(\S)+[@]{1}(\S)+[.]{1}(\w)+/;
        if(temp.value!="")
        {
            if(!myreg.test(temp.value))
            {
                document.getElementById("mail").innerHTML="請輸入有效的emailemail!";
                document.getElementById("mail").style.color="red";
                temp.value="";
                temp.focus();
                return false;
            }
            else{
                document.getElementById("mail").innerHTML="emailemail可以使用";
                document.getElementById("mail").style.color="green";
            }
        }
    } 

</script>

 

html  body部分

郵箱地址:<input id="email" name="email" onBlur="checkemail()" type="text" /><span id="mail"></span>&nbsp;<br>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章