我一直在寻找一个答案,并想知道是否有人有同样的问题。
jQuery.validation插件工作正常,通常,只是有几个URL没有正确验证,我正在努力找出原因(或有效的解决方法)。
普通URL工作正常,例如http://www.play.com ,但以下URL始终无法验证:
http://www.play.com/DVD/Blu-ray/4-/21404340/Transformers-3-Dark-Of-The-Moon-3D/Product.html?searchstring=&searchtype=allproducts&searchsource=2&searchfilters=ae212 {644651 }%2BC {600}%2b是urlrefer =搜索
我猜是因为{}字符。
我正在使用通用验证插件用法:
$("#myform").validate({ rules: { field: { required: true, url: true } } });任何有关此修复的见解都将非常感激。
I've been looking for an answer for this for a while now and wondering if anyone has had the same issue.
The jQuery.validation plugin works fine, normally, just there's a few URLs that it doesn't validate properly and I'm seriously struggling to figure out why (or a valid work-around).
Normal URLs work fine, such as http://www.play.com, but the following URL will always fail to validate:
http://www.play.com/DVD/Blu-ray/4-/21404340/Transformers-3-Dark-Of-The-Moon-3D/Product.html?searchstring=&searchtype=allproducts&searchsource=2&searchfilters=ae212{644651}%2bc{600}%2b&urlrefer=search
I'm guessing due to the { } characters.
I'm using the generic validation plugin usage:
$("#myform").validate({ rules: { field: { required: true, url: true } } });Any insight into a fix for this would be very appreciated.
最满意答案
是的,这些字符无效。 您可能希望采用的一个选项是在URL输入上有一个on change事件,用URI编码值替换当前值。
$('.url-field').change(function() { $(this).val(encodeURI($(this).val())); });Yes, those characters are invalid. One option you may wish to adopt is have an on change event on your URL input that replaces the current value with the URI encoded value.
$('.url-field').change(function() { $(this).val(encodeURI($(this).val())); });更多推荐
发布评论