时间:2022-03-02 09:06:55 | 栏目:JavaScript代码 | 点击:次
如下所示:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>在此处插入标题</title> <script type="text/javascript"> //判断用户输入的电子邮箱格式是否正确 function checkEmail(){ var myforms=document.forms; var myemail=myforms[0].email.value; var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/; if(myReg.test(myemail)){ return true; }else{ myspan.innerText="邮箱格式不对!"; return false; } } </script> </head> <body> <form action="#"> <table> <tr><td>邮箱:<input type="text" id=email></td><td><span id=myspan style="text-size:18pt;color:red;"></span></td></tr> <tr><td><input type="submit" value="提交" onclick="return checkEmail()"/></td><td></td></tr> </table> </form> </body> </html>