MongoDB+Struts2+JQuery.formValidator插件的web應用示例

 

 

 

 

 

 

 

 

 

db.properties

 

struts.xml

 

validator.js

<textarea cols="50" rows="15" name="code" class="javascript">$(document).ready(function(){ $.formValidator.initConfig({formid:"register",onerror:function(msg){alert(msg);return false;},onsuccess:function(){alert('ddd');return true;}}); $("#username").formValidator({tipid:"nameTip",onshow:"必填",onfocus:"用戶名至少6個字符,最多20個字符",oncorrect:"該用戶名可以註冊"}).inputValidator({min:6,max:20,onerror:"你輸入的用戶名不合法,請確認"}).regexValidator({regexp:"username",datatype:"enum",onerror:"用戶名格式不正確"}); $("#password").formValidator({tipid:"passwordTip1",onshow:"必填",onfocus:"密碼不能爲空,至少6位",oncorrect:"密碼輸入合法"}).inputValidator({min:6,empty:{leftempty:false,rightempty:false,emptyerror:"密碼兩邊不能有空格"},onerror:"密碼不能爲空,請確認"}); $("#password2").formValidator({tipid:"passwordTip2",onshow:"必填",onfocus:"兩次密碼輸入必須一致哦",oncorrect:"密碼確認正確"}).inputValidator({min:6,empty:{leftempty:false,rightempty:false,emptyerror:"重複密碼兩邊不能有空格"},onerror:"重複密碼不能爲空,請確認"}).compareValidator({desid:"password",operateor:"=",onerror:"兩次密碼輸入不一致,請重新確認"}); $(":radio[name='gender']").formValidator({tipid:"genderTip",onshow:"必填",onfocus:"默認爲男性",oncorrect:"性別選擇正確",defaultvalue:["0"]}).inputValidator({min:1,max:1,onerror:"性別忘記選了,請確認"}); $("#age").formValidator({onshow:"必填",onfocus:"請輸入年齡,範圍在18至100之間",oncorrect:"恭喜你,你輸對了"}).inputValidator({min:18,max:100,type:"value",onerrormin:"你輸入的值必須大於等於18",onerror:"年齡必須在18-100之間,請確認"}); $("#birth").focus(function(){WdatePicker({skin:'whyGreen',oncleared:function(){$(this).blur();},onpicked:function(){$(this).blur();}})}).formValidator({onshow:"必填",onfocus:"請選擇出生日期",oncorrect:"出生日期輸入合法"}).inputValidator({min:"1900-01-01",max:"2099-01-01",type:"date",onerror:"日期必須在/"1900-01-01/"和/"2099-01-01/"之間"}); $("#idCardNo").formValidator({onshow:"可選",onfocus:"請輸入15或18位身份證",oncorrect:"輸入正確"}).functionValidator({fun:isCardID}); $("#email").formValidator({onshow:"必填",onfocus:"必須輸入合法的郵箱地址",oncorrect:"郵箱填寫正確",forcevalid:true}).inputValidator({min:6,max:100,onerror:"郵箱地址的長度限制在6至100字符以內"}).regexValidator({regexp:"^([//w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([//w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onerror:"你輸入的郵箱格式不正確"}); $("#education").formValidator({onshow:"必填",onfocus:"請選擇真實的學歷",oncorrect:"學歷選擇正確"}).inputValidator({min:1,onerror: "學歷不能丟!"}); $(":checkbox[name='interests']").formValidator({tipid:"interestsTip",onshow:"必須選擇一個",onfocus:"得選擇1個",oncorrect:"興趣愛好已選"}).inputValidator({min:1,onerror:"沒選擇好哦"}); $("#telephoneNo").formValidator({empty:true,onshow:"可選",onfocus:"最好是留一下吧",oncorrect:"手機號碼填寫正確",onempty:"還真不留"}).inputValidator({min:11,max:11,onerror:"手機號碼必須是11位的,請確認"}).regexValidator({regexp:"mobile",datatype:"enum",onerror:"你輸入的手機號碼格式不正確"});; $("#phoneNo").formValidator({empty:true,onshow:"可選",onfocus:"格式例如:0755-66666666",oncorrect:"聯繫電話填寫正確",onempty:"哎,真得沒留"}).regexValidator({regexp:"^[[0-9]{3}-|/[0-9]{4}-]?([0-9]{8}|[0-9]{7})?$",onerror:"你輸入的聯繫電話格式不正確"}); $("#desc").formValidator({onshow:"必填",onfocus:"描述至少要輸入10個漢字或20個字符",oncorrect:"輸入合法",defaultvalue:"得寫點東東..."}).inputValidator({min:20,onerror:"你輸入的描述長度不正確,請確認"}); });</textarea> 

validator.css

<textarea cols="50" rows="15" name="code" class="css">.onCorrect { background:url(../images/reg4.gif) no-repeat; padding-left:25px; font-size: 12px; line-height:22px; vertical-align:middle; } .onShow { background:url(../images/reg1.gif) no-repeat; padding-left:25px; font-size: 12px; line-height:22px; vertical-align:middle; } .onFocus { background:#E9F0FF url(../images/reg2.gif) no-repeat; padding-left:25px; font-size: 12px; line-height:22px; vertical-align:middle; } .onError { background:#FFF2E9 url(../images/reg3.gif) no-repeat; padding-left:25px; font-size: 12px; line-height:22px; vertical-align:middle; } .onLoad { background:#E9FFEB url(../images/loading.gif) no-repeat 3px 3px; padding-left:25px; font-size: 12px; line-height:22px; vertical-align:middle; }</textarea> 

web.xml

 

 


 

 

 

 

 

 


發佈了29 篇原創文章 · 獲贊 3 · 訪問量 26萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章