Home  >  Article  >  Web Front-end  >  JavaScript to verify the legitimacy of the email

JavaScript to verify the legitimacy of the email

高洛峰
高洛峰Original
2016-11-26 14:45:121833browse

<script type="text/javascript">
 var sText = document.getElementById(&#39;mail&#39;).value;
//onblur 为控件失去焦点事件
 document.getElementById(&#39;mail&#39;).onblur = function sValue(){
  sText = this.value;
  var reMail =/^(?:[a-zA-Z0-9]+[_\-\+\.]?)*[a-zA-Z0-9]+@(?:([a-zA-Z0-9]+[_\-]?)*[a-zA-Z0-9]+\.)+([a-zA-Z]{2,})+$/;
  var s=new RegExp(reMail);
  if(s.test(sText))
 {alert("邮箱正确");}
  else//不正确清空
 {document.getElementById(&#39;mail&#39;).value="";}
 }
</script>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn