某些URL的jQuery验证错误(jQuery validation errors with certain URLs)

编程入门 行业动态 更新时间:2024-10-26 18:19:28
某些URL的jQuery验证错误(jQuery validation errors with certain URLs)

我一直在寻找一个答案,并想知道是否有人有同样的问题。

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())); });

更多推荐

本文发布于:2023-08-02 18:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   jQuery   URL   URLs   errors

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!