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>