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>
<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>
相关文章推荐
- ./upload/index.php
- Python学习笔记-列表1
- LeetCode 45 - Jump Game II
- 支付宝和微信支付封装
- 软件开发模式对比(瀑布、迭代、螺旋、敏捷)
- numpy.reshape
- Android——TV真机调试apk(android:sharedUserId="android.uid.system")转载
- Xamarin.Forms教程下载安装JDK配置环境变量
- 工厂模式详解
- TextView/EditText各种各样的效果
- oracle 11g安装教程 win7 64位
- 数据结构面试题
- $@
- FsRtlIsNameInExpression失败原因
- 98.Which statement is true regarding the COALESCE function?
- Android:30分钟弄明白Touch事件分发机制
- VS2012 项目引用了项目/DLL文件,也写了Using,但是编译时提示:未能找到类型或命名空间名称
- 指针数组与数组指针
- 字符编码问题
- NPOI 导出Excel图片 (网络)