Restrict special charater in Textbox by bootstrap validator

1.7k Views Asked by At
$('#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?

2

There are 2 best solutions below

0
Owais Aslam On

Use Regex to restrict special characters in validator

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