javascript平时小例子②(正则表达式验证邮箱)

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>邮箱正则</title>
</head>
<body>
<input type="text" id="Txt1" />
<input type="button" value="提交" id="btn1" />
<script>
window.onload=function(){
var oTxt=document.getElementById("Txt1");
var oBtn=document.getElementById("btn1");
oBtn.onclick=function(){
var re=/^\w+@[0-9a-z]+\.[a-z]+$/i;
if(re.test(oTxt.value))
{
alert("恭喜你,答案正确");
}
else
{
alert("对不起验证错误");
}
}

}
</script>
</body>
</html>

posted @ 2016-11-10 11:05  w宇小白  阅读(227)  评论(0编辑  收藏  举报