插件來自 http://validform.rjboy.cn/document.html
<!--ajax實時驗證用戶名--> <input type="text" value="" name="name" datatype="e" ajaxurl="valid.php?myparam1=value1&myparam2=value2" sucmsg="用戶名驗證通過!" nullmsg="請輸入用戶名!" errormsg="請用郵箱或手機號碼注冊!" /> <!--密碼--> <input type="password" value="" name="userpassword" datatype="*6-15" errormsg="密碼范圍在6~15位之間!" /> <!--確認密碼--> <input type="password" value="" name="userpassword2" datatype="*" recheck="userpassword" errormsg="您兩次輸入的賬號密碼不一致!" /> <!--默認提示文字--> <textarea tip="請在這里輸入您的意見。" errormsg="很感謝您花費寶貴時間給我們提供反饋,請填寫有效內容!" datatype="s" altercss="gray" class="gray" name="msg" value="">請在這里輸入您的意見。</textarea> <!--使用swfupload插件--> <input type="text" plugin="swfupload" class="inputxt" disabled="disabled" value=""> <input type="hidden" value="" pluginhidden="swfupload"> <!--使用passwordStrength插件--> <input type="password" errormsg="密碼至少6個字符,最多18個字符!" datatype="*6-18" plugin="passwordStrength" class="inputxt" name="password" value=""> <div class="passwordStrength" style="display:none;"><b>密碼強度:</b> <span>弱</span><span>中</span><span class="last">強</span></div> <!--使用DatePicker插件--> <input type="text" plugin="datepicker" class="inputxt" name="birthday" value="">
內置基本的datatype類型有: * | *6-16 | n | n6-16 | s | s6-18 | p | m | e | url
*:檢測是否有輸入,可以輸入任何字符,不留空即可通過驗證;
*6-16:檢測是否為6到16位任意字符;
n:數字類型;
n6-16:6到16位數字;
s:字符串類型;
s6-18:6到18位字符串;
p:驗證是否為郵政編碼;
m:手機號碼格式;
e:email格式;
url:驗證字符串是否為網址。
自定義datatype的名稱,可以由字母、數字、下划線、中划線和*號組成。
形如"*6-16"的datatype,Validform會自動擴展,可以指定任意的數值范圍。如內置基本類型有"*6-16",那么你綁定datatype="*4-12"就表示4到12位任意字符。如果你自定義了一個datatype="zh2-4",表示2到4位中文字符,那么datatype="zh2-6"就表示2到6位中文字符。
5.2版本之后,datatype支持規則累加或單選。用","分隔表示規則累加;用"|"分隔表示規則多選一,即只要符合其中一個規則就可以通過驗證,綁定的規則會依次驗證,只要驗證通過,后面的規則就會忽略不再比較。如綁定datatype="m|e",表示既可以填寫手機號碼,也能填寫郵箱地址,如果知道填入的是手機號碼,那么就不會再檢測他是不是郵箱地址;datatype="zh,s2-4",表示要符合自定義類型"zh",也要符合規則"s2-4"。
//需要引用的文件
<link rel="stylesheet" type="text/css" href="bootstrap3/css/bootstrap.css"> <link rel="stylesheet" type="text/css" href="Validform/css/style.css"> <script type="text/javascript" src="jquery-1.9.1.min.js"></script> <script type="text/javascript" src="Validform/js/Validform_v5.3.2.js"></script> <style type="text/css">
body{
background: #fff;
}
.form-control{ width: 300px; float: left; } .col-sm-10{ height: 34px; line-height: 34px; } </style> <script type="text/javascript"> $(function(){ // $(".registerform").Validform(); var demo=$(".registerform").Validform({ tiptype:3, label:".label", showAllError:true, datatype: { "zh1-6": /^[\u4E00-\u9FA5\uf900-\ufa2d]{1,6}$/ }, ajaxPost:true });
<input type="text" value="" class="inputxt" name="mobile" datatype="m|e" errormsg="賬號可以是手機或郵箱地址!" /> <input type="password" value="" class="inputxt" name="repassword" recheck="password" datatype="*6-18" errormsg="您兩次輸入的密碼不一致!" /> <input type="password" value="" class="inputxt" name="password" datatype="oldpassword,*6-18" errormsg="請設置新密碼(6-18位字符)!" /> $(".registerform").Validform({ tiptype:2, datatype:{ "zh1-6" : /^[\u4E00-\u9FA5\uf900-\ufa2d]{1,6}$/ oldpassword:function(gets){ if(gets==$("#passwordold").val()){ return "新密碼不能與舊密碼一致!"; } } }, ajaxPost:true });
-------------------------------------
datatype:"zh2-4" //2-4個漢字
datatype:"*6-20", //密碼6到20個
datatype="m" //電話號碼驗證
datatype="e" //郵箱格式驗證
errormsg = “ ” //驗證錯誤提示
nullmsg = “” //為空的提示
datatype="s6-18" //昵稱至少6個字符,最多18個字符
recheck 的值是它要對比的字段值
用","分隔表示規則累加
用"|"分隔表示規則多選一
datatype可以是正則,也可以是function函數
tiptype 可以為1、2 和 自定義函數。2 表示右側提示。
tiptype為 2 時,各表單元素對應顯示提示信息的對象,是在當前元素的父級的 next() 的子級中查找的