JS小练习-电子邮件地址验证

来源:互联网 发布:特效拍摄软件 编辑:程序博客网 时间:2024/04/26 18:59

<script language="javascript" type="text/javascript">
function checkEmail() {
 var email=document.form.email.value;
 if(email.length==0){
  alert("不能为空!");
  return false;
 } else if(email.indexOf("@",0)==-1){
  alert("邮件格式不对!/n缺少@符号!");
  return false;
 } else if(email.indexOf(".",0)==-1){
  alert("邮件格式不对!/n缺少.符号!");
  return false;
 } else{
  alert("OK");
 }


 /*
 if(email.indexOf("@",0)==-1){
  alert("邮件格式不对!/n缺少@符号!");
  return false;
 }
 if(email.indexOf(".",0)==-1){
  alert("邮件格式不对!/n缺少.符号!");
  return false;
 }
 return true;
 alert("OK");
 */


}
</script>
</head>

 

 

<body>
<form name="form" action="" method="post" onsubmit="checkEmail()">
<input id="email" name="email" type="text" /><input id="ok" name="ok" type="submit" value="认证" />
</form>
</body>

原创粉丝点击