0
$('#ad_pd_form').bootstrapValidator({ 
    fields: {           
        ad_pd_url: {
            validators: {
                notEmpty: {
                    message: 'Please enter a Valid URL'
                }
            }
        }
    }
    })

I need to restrict the user entering the special character in a text box. I'm using bootstrap validator to validate the form in the above code. User is only allowed to enter URL.

How can i restrict the special characters entering into it?

Irshu
  • 8,248
  • 8
  • 53
  • 65

2 Answers2

0

Use Regex to restrict special characters in validator

var nospecial=/^[^*|\":<>[\]{}`\\()';@&$]+$/;
validators: {
            notEmpty: {
                message: 'Please enter a Valid URL'
            },
            regexp: {
                regexp: nospecial,
                message: ' '
            }
         }
Owais Aslam
  • 1,577
  • 1
  • 17
  • 39
0
$('#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' 
                    }
            }
        }
    }
    })
Saravanan N
  • 585
  • 4
  • 15