Jquery VailDate初探

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>测试</title>
<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
<script src="js/jquery.validate-vsdoc.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$("#test1").validate({
rules: {
txtLoginIdName: {
required: true,
maxlength: 10,
minlength: 5
},
txtPwdName: {
required: true,
minlength: 2
},
confirm_pwdName: {
required: true,
equalTo: "#txtPwd"
}
},
messages: {
txtLoginIdName: "务必输入用户名",
txtPwdName: {
required: "务必输入密码",
minlengt: "最小长度为2",
maxlength: "最大长度10"
},
confirm_pwd: {
equalTo: "两次输入务必一致"
}
}
});
$.extend($.validator.messages, {
required: "必选字段",
remote: "请修正该字段",
email: "请输入正确格式的电子邮件",
url: "请输入合法的网址",
date: "请输入合法的日期",
dateISO: "请输入合法的日期 (ISO).",
number: "请输入合法的数字",
digits: "只能输入整数",
creditcard: "请输入合法的信用卡号",
equalTo: "请再次输入相同的值",
accept: "请输入拥有合法后缀名的字符串",
maxlength: $.validator.format("请输入一个长度最多是 {0} 的字符串"),
minlength: $.validator.format("请输入一个长度最少是 {0} 的字符串"),
rangelength: $.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
range: $.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
max: $.validator.format("请输入一个最大为 {0} 的值"),
min: $.validator.format("请输入一个最小为 {0} 的值")
});
});
</script>
</head>
<body>
<form id="test1" name="test1" method="POST" action="">
<span>用户名:</span><input type="text" id="txtName" name="txtLoginIdName" class="required" /><br />
<span>密 码:</span><input type="text" id="txtPwd" name="txtPwdName" /><br/>
<span>再次输入密码</span><input type="text" id="confirm_pwd" name="confirm_pwdName" />
<input type="submit" value="提交" name="subText" id="subText" />
</form>
</body>
</html>

小demo

vaildate是根据标签的name属性进行操作,

上一篇:JS组件系列——使用HTML标签的data属性初始化JS组件


下一篇:[推荐]ORACLE PL/SQL编程之四:把游标说透(不怕做不到,只怕想不到)