MVC3下的3种验证
(1):前台Jquery Validate脚本验证
引入脚本
<script src="../js/jquery.js" type="text/javascript"></script>
<script src="../js/jquery.validate.js" type="text/javascript"></script>
编写规则和错误信息
$().ready(function () {
$("#signupForm").validate({ rules: { //重要:这里是所有的规则 firstname: "required",
email: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
},
confirm_password: {
required: true,
minlength: 5,
equalTo: "#password"
}
},
messages: { //重要,这里是所有的错误消息 firstname: "请输入姓名",
email: {
required: "请输入Email地址",
email: "请输入正确的email地址"
},
password: {
required: "请输入密码",
minlength: jQuery.format("密码不能小于{0}个字 符")
}, confirm_password: {
required: "请输入确认密码",
minlength: "确认密码不能小于5个字符",
equalTo: "两次输入密码不一致不一致"
}
}
}); });
具体使用,参考网址:http://www.cnblogs.com/hejunrex/archive/2011/11/17/2252193.html
(2):MVC实体校验
(3):EF生成的/自己手写的 自定义实体校验(会运用到伙伴类+元数据共享)