【问题标题】:Restrict special charater in Textbox by bootstrap validator通过引导验证器限制文本框中的特殊字符
【发布时间】:2016-04-26 05:20:28
【问题描述】:
$('#ad_pd_form').bootstrapValidator({ 
    fields: {           
        ad_pd_url: {
            validators: {
                notEmpty: {
                    message: 'Please enter a Valid URL'
                }
            }
        }
    }
    })

我需要限制用户在文本框中输入特殊字符。我正在使用引导验证器来验证上述代码中的表单。用户只能输入 URL。

如何限制特殊字符输入?

【问题讨论】:

    标签: javascript jquery twitter-bootstrap jqbootstrapvalidation bootstrapvalidator


    【解决方案1】:

    使用正则表达式限制验证器中的特殊字符

    var nospecial=/^[^*|\":<>[\]{}`\\()';@&$]+$/;
    validators: {
                notEmpty: {
                    message: 'Please enter a Valid URL'
                },
                regexp: {
                    regexp: nospecial,
                    message: ' '
                }
             }
    

    【讨论】:

      【解决方案2】:
      $('#ad_pd_form').bootstrapValidator({ 
          fields: {           
              ad_pd_url: {
                  validators: {
                      notEmpty: {
                          message: 'Please enter a Valid URL'
                      },
                      // Url Validation
                      uri: {
                              message: 'The website address is not valid' 
                          }
                  }
              }
          }
          })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-13
        • 1970-01-01
        • 2019-06-24
        • 1970-01-01
        • 2013-05-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多