Can't get why URL custom validation method for jQuery validation plugin not working

泄露秘密 提交于 2020-01-15 09:43:30

问题


I'm trying to validate URL. I want to make these URLs pass the validation:

    www.site.com

    www.super.co.uk

I'm checking my RegEx in this site - http://www.rubular.com/

Here is my RegEx:

    /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/

It is working in Rubular site, but when I'm trying to use it in my custom jQuery validation Plugin method - it constantly tells me, that it is invalid:

     jQuery.validator.addMethod("complete_url", function(val, elem) {
// if no url, don't do anything
if (val.length == 0) { return true; }

    return /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/.test(val);
   });

   ...
   rules: {
         'website[url]': {
            required: true,
            url:  "complete_url",
            remote: {
            url: "http://127.0.0.1:3000/checkurl"
                  //url: "http://91.228.126.168:3000/checkurl"
            }
         }
        }

回答1:


/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/.test("www.super.co.uk"); returns true in chrome's console, so it is probably something with your plugin.



来源:https://stackoverflow.com/questions/12721471/cant-get-why-url-custom-validation-method-for-jquery-validation-plugin-not-work

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