jquery.validate.js實例演示


validate是前端重要的交互手段,提升性能的同時更能提升用戶操作體驗,validate的實現大概有三種方式:HTML5部分支 持,validate驗證框架,手動寫js或ajax調用接口。使用validate框架是非常方便的。這里提供一個validate的實例演示,http://cms.xlongwei.com/open/validate.html

實例代碼(演示頁面也可以查看源代碼):

<form action="/open/validate.html" method="post">
<label>用戶名 identifier:</label><input name="identifier" value="$!params.get('identifier')" class="{required:true,remote:{url:'http://cms.xlongwei.com/open/validate.json',type:'post',data:{type:'identifier',value:function(){ return $('input[name=\'identifier\']').val(); }}}}"><br/>
<label>銀行卡號 bankCardNumber:</label><input name="bankCardNumber" value="$!params.get('bankCardNumber')" class="{bankCardNumber:true,remote:{url:'http://cms.xlongwei.com/open/validate.json',type:'post',data:{type:'bankCardNumber',value:function(){ return $('input[name=\'bankCardNumber\']').val(); }}}}"><br/>
<label>正則 123a pattern:</label><input name="pattern" value="$!params.get('pattern')" class="{pattern:'\\d{3}[a-z]',remote:{url:'http://cms.xlongwei.com/open/validate.json',type:'post',data:{type:'/\\d{3}[a-z]/',value:function(){ return $('input[name=\'pattern\']').val(); }}}}"><br/>
<input type="submit">
</form>


validate擴展后支持(其中idNumber和bankCardNumber只校驗了數字和長度,末位校驗碼需要remote方式更准確地校驗)

money:true
chinese:true
mobile:true
tel:true
ip:true
plateNumber:true
idNumber:true
bankCardNumber:true
pattern:'\\d{3}[a-z]'


remote方式支持

{remnote:{url:'http://cms.xlongwei.com/open/validate.json',type:'post',data:{type:'',value:function(){return $('selector').val(); }}}}
type: identifier chinese numbers decimal money mobile email ip url tel idNumber plateNumber bankCardNumber organizationCode taxRegistrationNo


實例效果:

見筆者個人博客:https://www.xlongwei.com/detail/15091815


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM