Home > Web Front-end > JS Tutorial > body text

JavaScript to verify the legitimacy of the email

高洛峰
Release: 2016-11-26 14:45:12
Original
1851 people have browsed it

<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>
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template