使用jquery.validate.js实现boostrap3的校验和验证
使用jquery.validate.js实现boostrap3的校验和验证
boostrap3验证框架
jquery.validate.js校验表单
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
蕃薯耀 2015年9月15日 14:15:15 星期二
http://fanshuyao.iteye.com/
效果见下图:


一、插件下载
官网下载地址:http://jqueryvalidation.org/
或者在附件下载 jquery-validation-1.14.0.zip
二、加入js文件,依赖jquery
jquery.validate.min.js
additional-methods.min.js
messages_zh.min.js
additional-methods-custom.js (自己定义的校验方法扩展js文件)
三、验证表单
1、页面
<div class="w720 mt5 fr">
<div class="blue5 pt20 pb20 p10 user_password">
<form id="userInfoEditForm" class="form-horizontal">
<div class="form-group">
<label for="mobile" class="control-label">昵称:</label>
<div >
<input type="text" class="form-control" id="nickname" name="nickname" placeholder="请输入昵称" value="${userInSession.nickname}"/>
</div>
</div>
<div class="form-group">
<label for="mobile" class="control-label">姓名:</label>
<div>
<input type="text" class="form-control" id="realName" name="realName" placeholder="请输入真实姓名" value="${userInSession.realName}"/>
</div>
</div>
<div class="form-group">
<label for="tel1" class="control-label">性别:</label>
<div>
<select name="genders" id="genders" class="form-control">
<option value="">请选择…</option>
<c:forEach items="${genders}" var="gender">
<option value="${gender}" ${userInSession.genders eq gender?"selected='selected'":""}>${gender.value}</option>
</c:forEach>
</select>
</div>
</div>
<div class="form-group">
<label for="tel2" class="control-label">联系地址:</label>
<div>
<input type="text" class="form-control" id="address" name="address" placeholder="请输入联系地址" value="${userInSession.address}"/>
</div>
</div> <div class="form-group">
<div class="form-group-btn">
<button type="submit" id="btnUserInfoEdit2" class="btn btn-primary">确认</button>
</div>
</div>
</form>
</div>
</div>
2、js校验
var validateObj = $('#userInfoEditForm').validate({
ignore: "",
errorClass : 'help-block',
focusInvalid : true,
rules : {
nickname : {
required : true
},
realName : {
required : true
},
genders : {
required : true
/* ,select2Reg : true */
},
address : {
required : true
}
},
messages : {
nickname : {
required : "昵称不能为空"
},
realName : {
required : "姓名不能为空"
},
genders : {
required : "请选择性别"
},
address : {
required : "地址不能为空"
}
},
onclick : function (element) {
$(element).valid();
},
onfocusout: function (element) {
$(element).valid();
},
highlight : function(element) {
//alert($(element).closest('.form-group').html());
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
},
success : function(label) {
label.closest('.form-group').removeClass('has-error').addClass('has-success');
label.remove();
},
errorPlacement : function(error, element) {
element.parent('div').append(error);
},
submitHandler : function(form) {
return false;
form.submit();//form.submit(); 或者$(form).ajaxSubmit();
}
});
$("#genders").change(function(){
$(this).valid();
});
3、自定义校验方法(additional-methods-custom.js)
/**
* 检查手机号码
* @since 2015-09-14
*/
jQuery.validator.addMethod("phoneReg", function(value, element) {
var value = $(element).val();
console.log("value = "+value)
return this.optional(element) || (checkPhone(value));
}, "请输入正确的11位手机号码");
四、详细使用见:http://fanshuyao.iteye.com/blog/2243580
五、select2校验问题见
http://fanshuyao.iteye.com/blog/2243544
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
蕃薯耀 2015年9月15日 14:15:15 星期二
http://fanshuyao.iteye.com/
使用jquery.validate.js实现boostrap3的校验和验证的更多相关文章
- jquery.validate.js之自定义表单验证规则
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- jquery.validate.js默认配置,jquery.validate.js自定义提示信息
jquery.validate.js默认配置,jquery.validate.js自定义提示信息 配置jQuery.validator默认的处理方法 >>>>>>& ...
- jquery.validate.js remote (php)
网上的人不厚道呀 validate 这玩意的异步是 返回的 echo 'true' 或者 echo 'false';很少有人说呀~.~ 转载了一篇原文: jquery.validate.js对于数 ...
- 修改 jquery.validate.js 支持非form标签
尝试使用markdown来写一篇blog,啦啦啦 源代码传送门:github 在特殊情况下我们使用jquery.validate.js对用户输入的内容做验证的时候,表单并不是一定包含在form之中,有 ...
- 表单验证插件之jquery.validate.js
提到表单验证的插件,第一个想到的就是jquery.validate.js,所以小生想在这里稍微详细地说一下这款插件的具体使用方法,便于理解,我直接附上整段demo的代码(没怎么调样式,主要是看js): ...
- Jquery客户端校验——jquery.validate.js
jQuery Validate 插件为表单提供了强大的验证功能,让客户端表单验证变得更简单,同时提供了大量的定制选项,满足应用程序各种需求.该插件捆绑了一套有用的验证方法,包括 URL 和电子邮件验证 ...
- jQuery验证控件jquery.validate.js使用说明
官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...
- jquery.validate.js插件使用
jQuery验证控件jquery.validate.js使用说明+中文API 官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-valid ...
- jquery.validate.js表单验证
一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...
随机推荐
- [转贴]漫谈C语言及如何学习C语言
抄自http://my.oschina.net/apeng/blog/137911,觉得很有用,收藏它 目录:[ - ] 为什么要学习C语言? C语言学习方法 1,参考书籍 2,动手实验环境搭建 3, ...
- Xamarin IOS – hello word
原文:Xamarin IOS – hello word 环境 硬件:Macbook pro Retina 13 系统:10.11.3 EI Capitan Xcode:7.0 Ps:配置刚刚够用. 安 ...
- win8下光驱消失
导入这个注册表后重启,总算能读了..reg add "HKLM\System\CurrentControlSet\Services\atapi\Controller0" /f /v ...
- Ignatius and the Princess IV
Ignatius and the Princess IV Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K ( ...
- python 零散记录(七)(下) 新式类 旧式类 多继承 mro 类属性 对象属性
python新式类 旧式类: python2.2之前的类称为旧式类,之后的为新式类.在各自版本中默认声明的类就是各自的新式类或旧式类,但在2.2中声明新式类要手动标明: 这是旧式类为了声明为新式类的方 ...
- 现代Web的资源/类型/元素--发展趋势
5月6日,谷歌开发者中心推出了一个 Web 开发最佳实践手册.伯乐在线资源频道摘编该资源后,已邀请一些关注 Web 开发的朋友参与翻译手册. 由于译者朋友几乎都是已在职,都是在工作之余参与,每位的翻译 ...
- js函数参数设置默认值
php有个很方便的用法是在定义函数时可以直接给参数设默认值,如: function simue ($a=1,$b=2){ return $a+$b;}echo simue(); //输出3echo ...
- use isSubstring to check if one word is a rotation of another.
1: /// <summary> 2: /// Assume you have a method isSubstring which checks if one word is a s ...
- 支持Python 2.7的pylot
想用pylot测试一下板子上面的嵌入式web server.结果报错. E:\pylot_1.26>run.py -a 2 Traceback (most recent call last): ...
- Binggo公开课 “CODEX创新体系”的实战演练-中关村创业大街
Binggo公开课 "CODEX创新体系"的实战演练-中关村创业大街 Binggo公开课 "CODEX创新体系"的实战演练