formValidator js框架
Junda
posted @ 2012年3月28日 14:19
in 未分类
, 3035 阅读
昨天拿到一个前端传来的个人注册的页面,说里面可以完美的验证各个控件,然后有些许好奇,就去看了看。发现用了一个js的验证框架 名曰: formValidator 。
简单的看了看,还是基于jquery的一套玩意儿~ 用起来还是不错的,导入js后,基本只需要一句话就可以搞定
<link type="text/css" rel="stylesheet" href="${rooturl}js/from/validator.css"></link> <script src="${rooturl}js/from/formValidator-4.0.1.js" type="text/javascript" charset="UTF-8"></script> <script src="${rooturl}js/from/formValidatorRegex.js" type="text/javascript" charset="UTF-8"></script> <script src="${rooturl}js/jquery-1.7.2.min.js" language="javascript" type="text/javascript"></script>
上面是导入js,这里jquery用的是目前的最高版本,在用1.3.2的时候,自定义了一些代码报错,原因还没有细看。
$("#xingming").formValidator({ onShow:"请输入姓名", onFocus:"至少1个长度", onCorrect:"正确"}).inputValidator({ min:1, empty:{leftEmpty:false,rightEmpty:false,emptyError:"姓名两边不能有空符号"}, onError:"姓名不能为空,请确认"}); $("#password1").formValidator({ onShow:"请输入密码", onFocus:"至少1个长度", onCorrect:"密码合法"}).inputValidator({ min:1, empty:{leftEmpty:false,rightEmpty:false,emptyError:"密码两边不能有空符号"}, onError:"密码不能为空,请确认"}); $("#password2").formValidator({ onShow:"输再次输入密码", onFocus:"至少1个长度", onCorrect:"密码一致"}).inputValidator({ min:1, empty:{leftEmpty:false,rightEmpty:false,emptyError:"重复密码两边不能有空符号"}, onError:"重复密码不能为空,请确认"}).compareValidator({desID:"password1",operateor:"=",onError:"2次密码不一致,请确认"});
这是用户和密码的验证,不论是效果还是功能上都是很不错的。配置也比较简单。下面是通过ajax去验证用户名的有效性的方式
$(document).ready(function(){ $("#us").formValidator( {onShow:"请输入用户名",onFocus:"用户名至少5个字符,最多20个字符",onCorrect:"该用户名可以注册"}) .inputValidator({min:5,max:20,onError:"你输入的用户名非法,请确认"}) .ajaxValidator({ dataType : "html", data : encodeURI( $("#us").val()), async : true, url : "${rooturl}us/checkUserName", success : function(data){ if( data.indexOf("此用户名可以注册!") > 0 ) return true; if( data.indexOf("此用户名已存在,请填写其它用户名!") > 0 ) return false; return false; }, buttons: $("#button"), error: function(jqXHR, textStatus, errorThrown){alert("服务器没有返回数据,可能服务器忙,请重试"+errorThrown);}, onError : "该用户名已存在,请更换用户名", onWait : "正在对用户名进行合法性校验,请稍候..." }); });
相信有写过这样代码的同学或者有用过一些通过jquery的ajax方式调用servlet的方式实现功能的小插件的同学都应该不难看懂这样的东西。
整体来看功能还是一切ok的,扩展性也是ok的。这里不做太多解释,如有兴趣大家可以试用下,有问题可以一起探讨~
2013年3月01日 19:19
asdf
2015年7月02日 20:59
111111111111111111111
2024年1月16日 00:31
Great and an informative article! this wonderful post
2024年2月06日 18:42
Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards,
2024年2月06日 19:06
Another man complained that it wasn’t as much about the money, but the promise that he didn’t need to have any internet experience to be successful. I couldn’t find one satisfied buyer. There are many websites which solely in dedicated to Jeff Paul as a scam artist.
2024年2月06日 19:14
Superb web site, many thanks for finding the time to create these posts, i enjoy looking through all of them!
2024年2月06日 19:16
It’s probably just as easy or difficult to make money online through a blog as it is selling information products like yours. The key to BOTH is the ability to create a following/list of loyal listeners. That’s the hard part!
2024年2月06日 19:28
I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here!
2024年2月06日 19:36
This is my first time I visit here. I found so many engaging stuff in your blog, particularly its conversation. From the huge loads of remarks on your articles, I surmise I am by all account not the only one having all the recreation here! Keep doing awesome.
2024年2月06日 19:42
I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I’ll be sure to check back again real soon. what a brilliant post I have come across and believe me
2024年2月06日 19:54
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this
2024年2月06日 19:56
it’s really nice and meanful. it’s really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull
2024年2月06日 20:07
Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates.
2024年2月06日 20:16
I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while. Its as if you had a good grasp to the subject matter, but you forgot to include your readers. Perhaps you should think about this from far more than one angle. Or maybe you shouldnt generalise so considerably. Its better if you think about what others may have to say instead of just heading for a gut reaction to the subject. Think about adjusting your own thought process and giving others who may read this the benefit of the doubt.
2024年2月06日 20:26
Actually an incredible expansion. I have perused this great post. Gratitude for sharing data about it. I truly like that. Much appreciated so part for your assemble.
2024年2月06日 20:34
While i reputation I would in addition train tough created for your incorporate site would like While i embark on a lot of salubrious moreover retained up-to-date chaotic using your situation.
2024年2月06日 20:35
Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author!
2024年2月06日 20:42
Hmm… As i fully grasp weblogs having a linked problem, all the same as i do not ended pictures web page. As i added in from the piece that can help populars moreover i’ll quite possibly possibly be people specific primer.
2024年2月06日 20:47
The next time I learn a weblog, I hope that it doesnt disappoint me as much as this one. I imply, I do know it was my choice to learn, however I actually thought youd have something attention-grabbing to say. All I hear is a bunch of whining about something that you could possibly fix should you werent too busy looking for attention.
2024年2月06日 20:56
I hope this helps almost anyone searching for this type of topic. I think this website is the best for such topics. Good work and quality of article. Major site
2024年2月06日 21:04
When a blind man bears the standard pity those who follow…. Where ignorance is bliss ‘tis folly to be wise….
2024年2月06日 21:06
You have lifted a basic offspring..Blesss for using..I would need to think about better most recent exchanges from this blog..preserve posting..
2024年2月06日 21:12
One present why galore businesses opt for postcards is because they are overmuch cheaper to be prefab and this can forbear a lot of expenses on the lengthened run.
2024年2月06日 21:17
Thank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards,
2024年2月06日 21:22
Another man complained that it wasn’t as much about the money, but the promise that he didn’t need to have any internet experience to be successful. I couldn’t find one satisfied buyer. There are many websites which solely in dedicated to Jeff Paul as a scam artist.
2024年2月06日 21:28
Superb web site, many thanks for finding the time to create these posts, i enjoy looking through all of them!
2024年2月06日 21:29
It’s probably just as easy or difficult to make money online through a blog as it is selling information products like yours. The key to BOTH is the ability to create a following/list of loyal listeners. That’s the hard part!
2024年2月06日 21:35
I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here!
2024年2月06日 21:39
This is my first time I visit here. I found so many engaging stuff in your blog, particularly its conversation. From the huge loads of remarks on your articles, I surmise I am by all account not the only one having all the recreation here! Keep doing awesome.
2024年2月06日 21:47
I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I’ll be sure to check back again real soon. what a brilliant post I have come across and believe me
2024年2月06日 21:51
You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this
2024年2月06日 21:52
it’s really nice and meanful. it’s really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull
2024年2月06日 22:00
Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates.
2024年2月06日 22:59
I must say, as a lot as I enjoyed reading what you had to say, I couldnt help but lose interest after a while. Its as if you had a good grasp to the subject matter, but you forgot to include your readers. Perhaps you should think about this from far more than one angle. Or maybe you shouldnt generalise so considerably. Its better if you think about what others may have to say instead of just heading for a gut reaction to the subject. Think about adjusting your own thought process and giving others who may read this the benefit of the doubt.
2024年2月06日 23:07
Actually an incredible expansion. I have perused this great post. Gratitude for sharing data about it. I truly like that. Much appreciated so part for your assemble.
2024年2月06日 23:20
While i reputation I would in addition train tough created for your incorporate site would like While i embark on a lot of salubrious moreover retained up-to-date chaotic using your situation.
2024年2月06日 23:24
Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author!
2024年2月06日 23:25
Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author!
2024年2月06日 23:34
Hmm… As i fully grasp weblogs having a linked problem, all the same as i do not ended pictures web page. As i added in from the piece that can help populars moreover i’ll quite possibly possibly be people specific primer.