Skip to content Skip to sidebar Skip to footer

Bootstrap Form Validation Not Working

I am trying to validate username and password field using bootstrap validator I have included css and js for bootstrap validator. form id to validate is #login Code is as below

Solution 1:

Here is a working fiddle

The problem was that your js code contained in the fiddle contained syntax errors. The console should be the first thing you check when your javascript isn't working as expected. I commented in the code below what changes I made to get the fiddle to work. (It looks like the code in your question is fine though)

$(document).ready(function() {
    $('#login').bootstrapValidator({
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            userName: {
                validators: {
                    notEmpty: {
                        message: 'The first name is required and cannot be empty'
                    }
                }
            },
            password: {
                validators: {
                    notEmpty: {
                        message: 'The last name is required and cannot be empty'
                    }
                }
            } /* <-- removed unneeded comma */
        } /* <-- added closing brace */
    });
});

Post a Comment for "Bootstrap Form Validation Not Working"