jQuery Validate验证方法及教程
//实名认证 验证
$(function(){ //中文姓名验证
jQuery.validator.addMethod("zh_verify", function(value, element) {
var tel = /^[\u4E00-\u9FA5\uf900-\ufa2d]{2,10}$/;
return this.optional(element) || (tel.test(value));
}, "请输入2~10个字的中文!"); //身份证号验证
jQuery.validator.addMethod("idcard_verify", function(value, element) {
var idcard = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
return this.optional(element) || (idcard.test(value));
}, "请输入正确格式的身份证号!"); //jquery.validate插件验证
$("#nameauth").validate({
errorElement: 'div',
errorClass: 'help-block',
focusInvalid: false,
ignore: "",
rules: {
tname: {
required: true,
zh_verify:true
},
idcard: {
required: true,
idcard_verify:true
},
con_idcard: {
required: true,
equalTo: '.idcard'
}
},
messages: {
tname: {
required: "真实姓名不能为空!",
rangelength: "请输入2~18个中文!"
},
idcard: {
required: "身份证不能为空!",
rangelength: "请输入15~18个字符的身份证!"
},
con_idcard: {
required: "确认证号不能为空!",
equalTo: '确认证号与身份证号不一致!'
}
},
errorLabelContainer: "#resultMsg",
submitHandler:function() {
//$(form).ajaxSubmit(); //同步提交FORM
var tname = $('input[name=tname]').val();
var idcard = $('input[name=idcard]').val();
var resultMsg = $('#resultMsg');
ajaxSubmitForm(tname, idcard, resultMsg);
}
});
}) //异步执行方法
function ajaxSubmitForm(tname, idcard, resultMsg) {
$.ajax({
url: "/member/nameauth",
data: "tname=" + tname + "&idcard=" + idcard + "&con_idcard=" + idcard,
type: "post",
cache: false,
dataType: "json",
success: function(data, textStatus){
if(data.return){
window.location.reload();
}else{
resultMsg.css({'color': 'red'}).html(data.errmsg).show().delay(2000).hide(0);
}
}
});
}
或者
$(function(){
//jquery.validate插件自定义AJAX验证(验证账户是否存在)
$.validator.addMethod("checkUserExist",function(value,element){
var user = value;
$.ajax({
type:"POST",
async:true,
dataType:'json',
url:"/account/verifyAccount",
data:"param=" + $('input[name=newpassword]').val(),
success:function(response){
if(response){
res = response.state;
}
}
});
return res;
},"账号不存在,请仔细检查!");
//jquery.validate插件验证
$("#signupForm").validate({
rules: {
newpassword: {
required: true,
rangelength:[6,30]
}
},
messages: {
newpassword: {
required: "请输入6~30个字符的交易密码!",
rangelength: "请输入6~30个字符的交易密码!"
}
},
submitHandler:function(form) {
$(form).ajaxSubmit();
}
});
})
jQuery Validate教程
http://www.w3cschool.cc/jquery/jquery-plugin-validate.html
jQuery Validate验证方法及教程的更多相关文章
- 修改jQuery.validate验证方法和提示信息
1.添加验证方法 在jquery.validate.js文件中直接添加验证方法,例如: jQuery.validator.addMethod("Specialstring", fu ...
- jquery validate验证方法
实例: equalTo方法 equalTo(其他)返回:布尔 说明:要求元素与另一个元素相同 等于(其他) 其他 类型:选择器 元素的选择器用于比较当前值 例子: 使“字段”必须与#other相同 1 ...
- jQuery.Validate 验证,以及 remote验证, 多参数传递
jQuery.Validate 验证: http://www.runoob.com/jquery/jquery-plugin-validate.html 教程网址,很简单, 今天主要在这里记录一下re ...
- jQuery Validate验证框架详解
转自:http://www.cnblogs.com/linjiqin/p/3431835.html jQuery校验官网地址:http://bassistance.de/jquery-plugins/ ...
- jquery.validate 验证机制
jquery.validate 验证机制 金刚 juqery juqery.validate 在开发系统时,使用了jquery.validate.js 这个验证插件,来校验数据合法性 重点 验证是以i ...
- 弹出框页面中使用jquery.validate验证控件
弹出框页面中使用jquery.validate验证控件有几个问题需要解决: 1,弹出框的提交事件完成后如何关闭弹出框页面? 2,提交不成功如何返回当前页? 3,如果知道验证事件成功? 之前笔者都是JS ...
- 【转】jQuery Validate验证框架详解
jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导入js库 <script type=& ...
- jQuery Validate验证框架与 jQuery ajaxSubmit的联合使用
jQuery Validate验证框架自定义验证 第一步导入导入js库 <script src="<%=basePath%>static/js/jquery.js" ...
- atitit.jQuery Validate验证框架详解与ati Validate 设计新特性
atitit.jQuery Validate验证框架详解与ati Validate 设计新特性 1. AtiValidate的目标1 2. 默的认校验规则1 2.1. 使用方式 1.metadata用 ...
随机推荐
- Win7 安装 MongoDB
MongoDB 下载 MongoDB 提供了可用于 32 位和 64 位系统的预编译二进制包,你可以从MongoDB官网下载安装,MongoDB 预编译二进制包下载地址:https://www.mon ...
- CListCtrl设置选中行
原文链接: http://blog.163.com/lejianz@126/blog/static/11650292013610103232600/ CListCtrl 设置选中状态 1. 使用CLi ...
- C#中委托、事件和回调函数的理解
在C#中我们经常会碰到事件,尤其是在WPF或者WinForm中,窗体加载.或者点击一个按钮,都会触发事件.实际上,事件是对委托的封装.如果不进行封装,让委托暴露给调用者,调用者就可以把委托变量重新引用 ...
- 在ToolStrip中加入具有更好体验性的DateTimePicker
一. 需求的产生 很多时候,需要根据年月或日期来检索数据.在我的数据库中,如果只需要以月为单位,我一般按照200801这样的格式(yyyyMM)保存为int类型.在做数据检索时,是根据工具栏 ...
- Mysql命令行改动字段类型
在做微信公众平台 知识百科(账号:zhishiwiki) 时,由于字段先前设计的不合理.导致内容装不下,因此须要改动其字段类型为 text 这里使用到了 alter 命令 alter table 表名 ...
- Android Developers:保存文件
Android使用一个和其它平台基于硬盘文件系统相似的文件系统.这个课程描述了如何和在Android文件系统使用File APIs读和写文件. 一个File对象适用于读或者写从头到尾没用中断的大型数据 ...
- jmeter运行时间越久发送请求越来越少
displayed. Size: 412152 > 204800,而且每次点击查看“察看结果树”后会导致jmeter卡死, 解决方法: step1.在user.property中增加 view. ...
- nginx加载字体文件的时候报错
nginx 下加载配置 location ~* \.(eot|ttf|ttc|otf|eot|woff|woff2|svg)$ { root /web/static_jr ...
- SpringBoot+SpringAOP+Java自定义注解+mybatis实现切库读写分离
一.定义我们自己的切库注解类 自定义注解有几点需要注意: 1)@Target 是作用的目标,接口.方法.类.字段.包等等,具体看:ElementType 2)@Retention 是注解存在的范围,R ...
- centos安装Elasticsearch步骤
1.安装JDK:centos删除openJDK,安装JDK,vim /etc/profile配置JAVA_HOME 2.官网下载elasticsearch:https://www.elastic.co ...