您的位置:首页 > 其它

Form表单验证

2016-03-04 16:01 190 查看
<!DOCTYPE html>
<html>
<head>

<!--脚本内容-->
<script>
function validateForm(){
var x = document.forms["myForm"]["fname"].value;
var y = document.forms["myForm"]["fsex"].value;
if (x == null || x == ""){
alert("姓必须填写");
return false;
}
if (y == null || y == ""){
alert("性别必须填写");
if(){

}
return false;
}
var z = document.forms["myForm"]["email"].value;
var atpos = z.indexOf("@");
var dotpos = z.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=z.length)
{
alert("Not a valid e-mail address");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" action="xxx.do" onsubmit="return validateForm()" method="post">
姓名: <input type="text" name="fname">
性别: <input type="text" name="fsex">
Email: <input type="text" name="email">
<input type="submit" value="提交">
</form>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: