本文實例講述了JS驗證郵件地址格式方法。分享給大家供大家參考,具體如下:
示例1:
function checkRate(input){ var re = /^[_".0-9a-z-]+@([0-9a-z][0-9a-z-]+".){1,4}[a-z]{2,3}$/i; var nubmer = document.getElementById(input).value; if (!re.test(nubmer)) { alert("請輸入正確格式的郵件地址"); document.getElementById(input).value = ""; return false; }}示例2:
<script type="text/javascript">function isValidMail() { var TextVal = document.getElementById("TextBox1").value; var Regex = /^(?:/w+/.?)*/w+@(?:/w+/.)*/w+$/; if (Regex.test(TextVal)){ alert(true); } else { if (TextVal == "") { alert("請輸入電子郵件地址!!"); return false; } else { alert("您好,你輸入不正確,請重新輸入;"); document.getElementById("TextBox1").value = ""; return false; } }}</script>希望本文所述對大家JavaScript程序設計有所幫助。
新聞熱點
疑難解答