zoukankan      html  css  js  c++  java
  • jquery validate 自定义校验方法

    1.引入JS

    jquery.min.js
    jquery.validate.min.js
    messages_zh.min.js

    2.添加验证方法,第一个参数为验证方法的名称,第二个参数为验证方法。

    $.validator.addMethod("money",function(value,element,params){ 
            if (value == "" || value == null){
                return true;
            }
            var reg = /d+(.d{1,2})?/;  
            if(!reg.test(value)) {
                return false;
            } else{
                return true;
            }
        },"*请输入正确售价");  

    3.为表单添加验证方法。rules 里面的属性指的是需要验证的标签名称,方法后面可以传参数,多个参数用[ ],逗号隔开

      $().ready(function() {
            // 在键盘按下并释放及提交后验证提交表单
              $("#searchFrom").validate({
                rules: {
                    searchParam: {
                        money:""
                   }
                }
                });
        });    

    4.效果

  • 相关阅读:
    Business
    Triple Inversions
    protobuf
    16.04 ubuntu python3.6 install
    1.安装
    Tutorial2
    Tutorial1
    geometry_msgs的ros message 类型赋值
    UBUNTU QQ/TIM的救星
    ubuntu17.10升级到ubuntu18.04 LTS
  • 原文地址:https://www.cnblogs.com/li-zhi-long/p/9289245.html
Copyright © 2011-2022 走看看