我們可以使用JavaScript編寫以下腳本,驗(yàn)證用戶輸入的郵件地址的有效性。
<> <> < language="Javascript1.2"> <!-- start hiding function verifyAddress(obj) { var email = obj.email.value; var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; flag = pattern.test(email); if(flag) { alert(“Your email address is correct!”); return true; } else { alert(“Please try again!”); return false; } } // stop hiding --> </script> </head> <> < onSubmit="return verifyAddress(this);"> < name="email" type="text"> < type="submit"> </form> </body> </html>
|