jQuery EasyUI提交表單驗證,jqueryeasyui

來源:互聯網
上載者:User

jQuery EasyUI提交表單驗證,jqueryeasyui

EasyUI的form表單裡面的驗證框,先講解下validatebox類和相關的屬性。

驗證規則

驗證規則是通過使用 required 和 validType 特性來定義的, 這裡是已經實施的規則:

email:匹配 email Regex規則,系統提供的屬性。

url:匹配 URL Regex規則

length[0,100]:允許從 x 到 y 個字元

remote['http://.../action.do','paramName']:發送 ajax 請求來驗證值,成功時返回 'true' 。

要自訂驗證規則,重寫 $.fn.validatebox.defaults.rules ,來定義一個驗證函式和無效的資訊。例如,定義一個 minLength 驗證類型:

$.extend($.fn.validatebox.defaults.rules, { minLength: { validator: function(value, param){ return value.length >= param[0]; }, message: 'Please enter at least {0} characters.' } }); 

調用 validate 方法並且返回驗證結果,true 或者 false。

<div id="userReg" class="easyui-panel" style="width:400px; height:300px;" title="註冊使用者"> <form action="" method="post"> <table> <tr> <td>使用者名稱:</td> <td><input type="text" name="username" class="easyui-validatebox" required=true validType="midLength[4,10]" value=""/></td> </tr> <tr> <td>密碼:</td> <td><input type="text" name="password" class="easyui-validatebox" required=true validType="pwdLength[8]" value=""/></td> </tr> <tr> <td>性別:</td> <td> <input type="radio" name="sex" checked="checked" value="male"/>男 <input type="radio" name="sex" value="female"/>女 </td> </tr> <tr> <td>年齡:</td> <td><input type="text" name="age" value=""/></td> </tr> <tr> <td>出生日期:</td> <td><input type="text" name="birth" value=""/></td> </tr> <tr> <td>所屬城市:</td> <td><input type="text" name="city" value=""/></td> </tr> <tr> <td>薪水:</td> <td><input type="text" name="salary" value=""/></td> </tr> <tr> <td colspan="2"> <a class="easyui-linkbutton">儲存</a> </td> </tr> </table> </form> </div> <script type="text/javascript"> $(function(){ $.extend($.fn.validatebox.defaults.rules,{ midLength:{ validator:function(value, param){ return value.length >= param[0] && value.length<=param[1]; }, message: '使用者名稱必須在4到10位之間!' }, pwdLength:{ validator:function(value,param){ return value.length==param[0]; }, message:'密碼必須是8位' } }); }); </script> 

參考圖片如下:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.