您现在的位置:首页 >> 前端 >> 内容

正则表达式之邮箱验证

时间:2017/7/25 11:36:16 点击:

  核心提示:正则表达式之邮箱验证!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN https://www.w3.org/TR/xhtml1/D...
正则表达式之邮箱验证
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
window.onload=function(){
var oTxt=document.getElementById('txt1');
var oBtn=document.getElementById('btn1');

oBtn.onclick=function(){

             //邮箱验证
var re=/^\w+@[a-z0-9]+\.[a-z]+$/i;

if(re.test(oTxt.value)){

alert('合法的邮箱');

}
else{

alert('邮箱不合法');
} 

}


}






</script>
</head>


<body>
<input id="txt1" type="text" /></body>
<input type="button" value="验证" id="btn1" />


</body>
</html>

 

作者:网络 来源:ywxiaochen