代碼: <script type="text/javascript"> //驗證郵箱格式 function isEmail() { var email=document.getElementById("zh_e").value; if(email=="") { alert("請輸入郵箱!"); document.getElementById("zh_e").focus(); return false; } var pattern= /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/; strEmail=pattern.test(email); if (strEmail) { return true; } else { alert("郵箱格式不正確!"); } } </script> 實現(xiàn)功能:當鼠標焦點離開文本框時觸發(fā)該事件。onblur=“isEmail” [ onblur()失去焦點時觸發(fā)事件 ] html: <input type="text" maxlength="32" style="width:220px;" onblur="isEmail()" id="zh_e"/>
|
|