Home > Article > Web Front-end > JavaScript to verify the legitimacy of the email
<script type="text/javascript"> var sText = document.getElementById('mail').value; //onblur 为控件失去焦点事件 document.getElementById('mail').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('mail').value="";} } </script>