jquery.validate.js实例演示

為{幸葍}努か 提交于 2020-08-17 16:16:42

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!