【问题标题】:how to validate Jquery plugin url without http or https?如何在没有 http 或 https 的情况下验证 Jquery 插件 url?
【发布时间】:2018-11-07 16:30:25
【问题描述】:

我想验证没有httphttps 的网址。 我正在使用 JQuery 之类的东西:

$("#add_users_form").validate({
        ignore: [],
        rules: {
            'user_detail[website]': {
                url: true
            },
  }
    }); 

【问题讨论】:

    标签: jquery validation plugins


    【解决方案1】:

    @anand,您需要为此添加自定义验证方法,请使用以下脚本

    // add custom validation method 
    jQuery.validator.addMethod("checkurl", function(value, element) {                                       
        return /^(www\.)[A-Za-z0-9_-]+\.+[A-Za-z0-9.\/%&=\?_:;-]+$/.test(value);
        }, "Please enter a valid URL."
    );
    
    
     // connect it to a css class
      jQuery.validator.addClassRules({
            checkurl : { checkurl : true }    
     });
    
    
    'website[url]': {
            checkurl: true
    }
    

    【讨论】:

    • 我正在使用 jquery validate 插件,我已经尝试过这些代码但没有解决我的问题。
    • 我认为你是新手。你知道如何应用吗?
    猜你喜欢
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    相关资源
    最近更新 更多