1. 程式人生 > >jquery-validator.js外掛校驗

jquery-validator.js外掛校驗

首先引入檔案

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.metadata.js" type="text/javascript"></script>
<script src="jquery.validate.js" type="text/javascript"></script>

在JS裡配置檔案 名字針對標籤的屬性name

//配置校驗引數 
$().ready(function(){
$("#dbform").validate({
  rules:{
  f_52_insroot_2:"slywlx",
  f_52_insroot_4:"dateISO",
  f_52_insroot_5:"required",
  f_52_insroot_6:"required",
  f_52_insroot_7:"required",
  f_52_insroot_8:{required:true,checkcard:"f_52_insroot_6"},
  f_52_insroot_9:{required:true,checkcard:"f_52_insroot_7"},
  f_52_insroot_10:{required:true,isIdCardNo:"f_52_insroot_8"},
  f_52_insroot_11:{required:true,isIdCardNo:"f_52_insroot_9"},
  f_52_insroot_12:"required",
  f_52_insroot_13:"required",
  f_52_insroot_14:{required:true,dateISO:true,iscanmarry:"男"},
  f_52_insroot_15:{required:true,dateISO:true,iscanmarry:"女"},
  f_52_insroot_20:{junren:"f_52_insroot_8"},
  f_52_insroot_21:{junren:"f_52_insroot_9"},
  f_52_insroot_24:{required:true,jhlb:"f_52_insroot_25"},
  f_52_insroot_25:{required:true,jhlb:"f_52_insroot_24"},
  f_52_insroot_26:{required:true,jhlbyhyzk:"f_52_insroot_24"},
  f_52_insroot_27:{required:true,jhlbyhyzk:"f_52_insroot_25"},
 
  },
  messages:{
  f_52_insroot_4:"受理日期格式不正確",
  f_52_insroot_5:"請選擇是否為補辦婚姻",
  f_52_insroot_6:"請選擇男方人員類別",
  f_52_insroot_7:"請選擇女方人員類別",
  f_52_insroot_8:{required:"請選擇男方身份證類別",checkcard:"男方身份證類別選擇不正確"},
  f_52_insroot_9:{required:"請選擇女方身份證類別",checkcard:"女方身份證類別選擇不正確"},
  f_52_insroot_10:{required:"請輸入男方身份證件號碼",isIdCardNo:"男方身份證號碼不正確"},
  f_52_insroot_11:{required:"請輸入女方身份證件號碼",isIdCardNo:"女方身份證號碼不正確"},
  f_52_insroot_12:"請輸入男方姓名",
  f_52_insroot_13:"請輸入女方姓名",
  f_52_insroot_14:{required:"請輸入男方出生日期",dateISO:"男方出生日期格式不正確",iscanmarry:"男方未滿法定婚齡"},
  f_52_insroot_15:{required:"請輸入女方出生日期",dateISO:"女方出生日期格式不正確",iscanmarry:"女方未滿法定婚齡"},
  f_52_insroot_20:{junren:"男方職業選擇不正確"},
  f_52_insroot_21:{junren:"女方職業選擇不正確"},
  f_52_insroot_24:{required:"請選擇男方結婚類別"},
  f_52_insroot_25:{required:"請選擇女方結婚類別"},
  f_52_insroot_26:{required:"請選擇男方婚姻狀況",jhlbyhyzk:"男方結婚類別和婚姻狀況不一致"},
  f_52_insroot_27:{required:"請選擇女方婚姻狀況",jhlbyhyzk:"女方結婚類別和婚姻狀況不一致"},
  },
  errorContainer: $('div.container'), 

  });
 

  });    

自定義函式檢驗

//男女結婚類別校驗
   $.validator.addMethod("jhlb",function(value,element,param){        //value是輸入的值,param是配置檔案輸入的引數
      var index=document.getElementsByName(param)[0].selectedIndex;
        var jhlb=document.getElementsByName(param)[0].options[index].text;
          if (value == '初婚') {
         if (jhlb != '初婚' && jhlb != '再婚') {
           return false;
         }
       }      
       if (jhlb != '復婚' && value == '復婚') {
        return false;
       }      
       return true;
   },'雙方結婚類別矛盾');

分別在每個檢驗的輸入框後自動生成錯誤提示

頁面的顯示框 <div class="container" style="display: none">輸入有誤</div>

相關推薦

jquery-validator.js外掛

首先引入檔案 <script src="jquery.js" type="text/javascript"></script> <script src="jquery.metadata.js" type="text/javascript">

jQuery validator 表單基本用法

jQuery validator 是一款基於jQuery的表單驗證外掛, 非常方便實用。 例: 使用前引入需要的js: <script src="http://static.runoob.com/assets/jquery-validation-1.14.0/lib/jquer

jQuery.validator 自定義規則

//自定義校驗方法             jQuery.validator.addMethod("gt", function (value, param) {   

jQuery的表單外掛validate(轉)

今天試了一下,還是比較方便的,主要是可以與jQuery結合起來做到與HTML分離. 官網的例子裡引用了幾個js和css檔案,但只需引用jquery.validate.js這一個檔案即可.

jQuery.validate 的form

是我 顯示 用戶 put text 運行 scl htm 表單 jQuery驗證框架 : 基本html代碼: 1   <script src="js/jquery-1.9.1.js"></script> 2 <script src

Jquery Validate 默認規則及常用的自定義驗證規則

字符 eth ber exp string amp 手機 zip 子郵件 Jquery Validate 相關參數及常用的自定義驗證規則 一、官網地址:http://bassistance.de/jquery-plugins/jquery-plugin-validatio

extjs/js時間

獲取 時間差 小寫 含義 月份 sunday 一個 ember nbsp //時間秒判斷var re=/^(?:19|20)[0-9][0-9]-(?:(?:0[1-9])|(?:1[0-2]))-(?:(?:[0-2][1-9])|(?:[1-3][0-1])) (?:(

SpringBoot 的 Validator 的註解

@null           驗證物件是否為空 @notnull     驗證物件是否為非空 @asserttrue  

jquery.validate手動呼叫

這兩天在做iframe巢狀的功能,關於iframe頁面中的一些校驗問題,需要用到手動jquery.validate的情況,先在做以記錄,方便日後檢視,程式碼如下: //載入jquery的校驗方法 $("#inputForm").validate({ errorContainer: "#mess

Vant async-validator 表單

感謝:尤大大的 vue、有讚的 vant、async-validator、以及 asseek 連結:https://www.jianshu.com/p/d58fe749b97f 在下不才在 asseek 的基礎上加入了一些自己的想法有了現在的版本。拋磚引玉請多多提點。

SSM-SpringMVC中利用hibernate-validator做後臺

執行環境idea2018.2+maven3.5.4+jdk1.8+tomact8.5.34 一、第一步:引入包 在pom.xml中新增包,maven即可自動下載  <!--資料驗證-->  <dependency>     &n

Hibernate Validator服務端

         Hibernate Validator 是 Bean Validation 的參考實現。Hibernate Validator 提供了 JSR 303 規範中所有內建 constraint(約束) 的實現,除此之外還有一些附加的 c

js

1、判斷是否為數字(整數、小數) //使用isNaN()函式 //isNaN()的缺點就在於 null、空格以及空串會被按照0來處理 //isNaN: Not a Number function isRealNum(val){ // isNaN()函式 把空串 空格 以及NU

easyui快捷鍵實現增刪改(jquery.hotkeys.js外掛)

第一步:下載 jquery.hotkeys.js外掛  http://plugins.jquery.com/hotkeys/ 第二步:js引入 <!-- jquery的按鍵擴充套件支援 --> <script type="text/jav

Spring Boot 使用hibernate validator進行引數

demo 實體類 public class UserBean { @NotBlank(message="使用者名稱不能為空") private String userName; @NotBlank(message="年齡不能為空") @P

js資料【自用】

/** * 驗證密碼複雜度(必須包含數字字母) * @param str * @returns true:滿足規則,false:不滿足 */ function validateStr(str){ var reg1 = /^(([0-9]{1,})([a-z]{1

Java使用Validator進行Bean

工具類 package com.yjy.util; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import com.google.common.

jquery.cookie.js外掛

jquery.cookie.js外掛:   <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script> <script type="text/ja

SpringBoot+jquery 登入+驗證碼

展示頁面    首先我貼上前端程式碼 <div class="container"> <div class="col-md-4 location"> <div class="form-signin

jquery.fileupload.js外掛使用--單視訊或音訊上傳預覽

一、前臺程式碼: <!DOCTYPE html> <html> <head> <title>jquery.fileupload.js使用測試</title> <script src="jqu