主页 M

检查Email的书写格式是否正确的代码

2014-10-06 网页编程网 网页编程网

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>EMAIL检验</title>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!--
function check()
{
 if(document.register.email.value.length!=0)
  {
    if (document.register.email.value.charAt(0)=="." ||        
         document.register.email.value.charAt(0)=="@"||       
         document.register.email.value.indexOf('@', 0) == -1 || 
         document.register.email.value.indexOf('.', 0) == -1 || 
         document.register.email.value.lastIndexOf("@")==document.register.email.value.length-1 || 
         document.register.email.value.lastIndexOf(".")==document.register.email.value.length-1)
     {
      alert("Email的格式不正确!");
      document.register.email.focus();
      return false;
      }
   }
 else
  {
   alert("Email的不能为空!");
   document.register.email.focus();
   return false;
   }
 return false;

//-->
</SCRIPT>
<form name="register" method="POST" action onSubmit="return  check();">
<p align="center">
  Email:<input type="text" name="email" size="20">
  <input type="submit" value="提交" name="B1">
  <input type="reset" value="重填" name="B2">
</p>
</form> 
</body>
</html> 

阅读原文
阅读 3676
123 显示电脑版