jQuery表單驗證外掛程式formValidation實現個人化錯誤提示

來源:互聯網
上載者:User

上期在[jQuery外掛程式Validate驗證表單實現javascript表單驗證功能]和[jQuery外掛程式Validation驗證表單實現javascript表單智能驗證功能]中分別介紹了兩個實現表單驗證的jQuery外掛程式,這裡介紹另外一個表單驗證外掛程式formValidation,這個外掛程式與前面兩個外掛程式的最大區別在於它實現了個人化的錯誤提示資訊,顯示在表單元素右上方類似於提示條,其如下:

使用說明

需要使用jQuery庫檔案和formValidation庫檔案[下載執行個體代碼]
http://jquery.com/

同時需要自訂顯示提示錯誤資訊的CSS樣式

使用執行個體

一,包含檔案部分

  1. <script src="jquery.js" type="text/javascript"></script>
  2. <script src="jquery.validationEngine.js" type="text/javascript"></script>
  3. <link rel="stylesheet" href="validationEngine.jquery.css" type="text/css" media="screen" />

二,HTML部分

  1. <input class="validate[required,custom[onlyLetter],length[0,100]]" name="firstname" type="text" />

formValidation外掛程式的表單驗證方法如下:

  1. validate[required,custom[onlyLetter],length[0,100]]

參數說明:required表示表單必填,custom[]表示驗證的條件,length表示長度

formValidation外掛程式其它說明:

optional: Special: 表單值不為空白的情況

required: 必埴

length[0,100] : 長度範圍

minCheckbox[7] : 最小複選框數

confirm[fieldID] : 匹配其它欄位 (如:confirm password)

telephone : 匹配電話號碼規則

email : 匹配電子郵箱規則

onlyNumber : 匹配數字規則

noSpecialCaracters : 匹配字元規則

onlyLetter : 匹配字母規則

date : 匹配 YYYY-MM-DD 格式

formValidation外掛程式應用執行個體

一,驗證單選框

  1. <input class="validate[required] radio" type="radio" name="radiogoupe" value="5">
  2. <input class="validate[required] radio" type="radio" name="radiogoupe" value="3"/>
  3. <input class="validate[required] radio" type="radio" name="radiogoupe" value="9"/>

二,驗證複選框

  1. <input class="validate[minCheckbox[2]] checkbox" type="checkbox" name="checkboxgroupe" value="5">
  2. <input class="validate[minCheckbox[2]] checkbox" type="checkbox" name="checkboxgroupe" value="3"/>
  3. <input class="validate[minCheckbox[2]] checkbox" type="checkbox" name="checkboxgroupe" value="9"/>

三,驗證下拉框

  1. <select name="sport" id="sport" class="validate[required]" >
  2. <option value="1">biuuu_1</option>
  3. <option value="2">biuuu_2</option>
  4. <option value="3">biuuu_3</option>
  5. <option value="4">biuuu_4</option>
  6. </select>

四,驗證電話號碼

  1. <input class="validate[required,custom[telephone]] text-input" type="text" name="telephone"/>

五,驗證郵箱

  1. <input class="validate[required,custom[email]] text-input" type="text" name="email" id="email" />

如上執行個體,使用formValidation外掛程式實現表單驗證方法比較簡單,主要在於其實現的個人化錯誤提示,同時,可自訂匹配規則,如下:

  1. "telephone":{
  2. "regex":"/^[0-9-()]+$/",
  3. "alertText":"* Invalid phone number"},

其中regex表示匹配規則

這樣使用alertText就可以實現自訂的表單錯誤提示文本,這與Validation外掛程式的使用方法相同,使用jQuery表單驗證外掛程式formValidation實現個人化錯誤提示,值得推薦。

點我下載jQuery外掛程式formValidation執行個體原始碼
http://jquerycodes.googlecode.com/files/formValidator.zip

相關文章

jQuery外掛程式Validate驗證表單實現javascript表單驗證功能

jQuery外掛程式Validation驗證表單實現javascript表單智能驗證功能

原創文章如轉載,請註明:轉載自 必優部落格 http://www.biuuu.com/

本文連結地址:http://www.biuuu.com/?p=1104

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.