js验证邮件格式

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function verifyAddress(obj)
{
 var email = document.haha.address.value;
 var pattern = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
 flag = pattern.test(email);
 if(flag)
 {
  alert("通过验证");
 return true;
 }
 else
  {
if(email=='')
{
alert("邮件地址不能为空");
return false;
}else
{


   alert("邮件格式不对");
   return false;
   }
}
}
</script>
</head>
<body>
<form action="" name="haha">
<input type="text" name="youjian" id="address">
<input type="submit" value="验证" onclick="verifyAddress(this);">
</form>
</body>
</html>

你可能感兴趣的:(JavaScript,html)