今天使用jquery.validate.js表单验证

本文介绍了如何利用jquery.validate.js库进行表单验证,特别是针对中文输入的验证规则。通过添加自定义方法`isChinese`实现中文字符的检查,并展示了在表单验证中的应用,包括设置验证规则和提示信息。
摘要由CSDN通过智能技术生成

今天使用jquery.validate.js表单验证

使用metronic中的两个js文件

jquery.validate.min.js

form-wizard.js


目前只会使用三个方面:

// 1.在validator中插入中文输入验证规则
jQuery.validator.addMethod("isChinese", function(value, element) {
var chinese = /^[\u4e00-\u9fa5]{1,20}$/g;
return this.optional(element) || (chinese.test(value));
}, "请填写中文。");

//2.检测表单输入信息

var form = $('#submit_form');

form.validate({
                doNotHideMessage: true, //this option enables to show the error/success messages on tab switch.
                errorElement: 'span', //default input error message container
                errorClass: 'help-block help-block-error', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                //2.1配置name=mctName的输入限制规则。

rules: {
//商户信息
mctName: {
required: true ,
isChinese: true
}

}

//2.2配置提示信息

messages: { // custom messages for radio buttons and checkboxes
mctName:{
required : "请输入商户名称"
}

}

});


效果如图:



具体函数可以查看jquery.validate.js   API



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值