js电子邮箱验证代码

来源:互联网 发布:网络主播视频 编辑:程序博客网 时间:2024/05/01 13:30

js电子邮箱验证代码
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>js电子邮箱验证代码</title>
<script language="javascript">
 //电子邮件校验
 function $(id)
 {
  return document.getelementbyid(id);
 }
 
 function isemail(imail){  
 
   var emailpattern = /^w+((-w+)|(.w+))*@[a-za-z0-9]+((.|-)[a-za-z0-9]+)*.[a-za-z0-9]+$/; 
   var imail = $('email').value;  
   if (emailpattern.test(imail)==false)
   {
     $('inner').innerhtml ='邮箱地址有误,你重新输入!';
     myfm.email.focus();    
     return false;
   }  
   else
   {
    $('inner').innerhtml ='正确';
    return true; 
   }
 }
 

</script>

<style type="text/css">
 #inner{color:#f00;}
</style>

</head>

<body>
<form id="form1" name="myfm" method="post" action="">
  <label for="email"></label>
  <input type="text" name="email" id="email" />
  <input type="button" name="button"  value="邮箱验证" onclick="javascript:return isemail(this.value);" />
  <div id="inner"></div>
</form>
</body>
</html>
这段邮箱验证代码是一款javascript做的,在客户端验证实例代码。本站原创www.111cn.net转载注明来源