这里写的是在JSP页面通过正则表达式验证邮箱是否正确
看代码吧!
<script language="javascript" type="text/javascript">
function check_mail(e){
if(!/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(e))
{
alert("请输入格式正确的 e-mail 地址!");
}
}
</script>
<body>
<form name="registerform" action="<%=basePath%>user/userRegister" method="post" >
<input type="text" name="u_mail" value="邮箱" onblur="check_mail(document.getElementsByName('u_mail')[0].value)"/>
<div>
<button class='register_button' type="submit" >
注册
</button>
</form>
</body>