1、js代码
<script type="text/javascript"> /** * 验证邮箱格式 * http://www.jb200.com */ function validate_email(field, alerttxt) { with (field) { apos = value.indexOf("@") dotpos = value.lastIndexOf(".") if (apos < 1 || dotpos - apos < 2) { alert(alerttxt); return false } else { return true } } } function validate_form(thisform) { with (thisform) { if (validate_email(email, "Not a valid e-mail address!") == false) { email.focus(); return false } } } </script>
2、html页面
<form action=""onsubmit="return validate_form(this);" method="post"> Email: <input type="text" name="email" size="30"> <input type="submit" value="Submit"> </form>