Bootstrap validator plugin for validate form fields
Posted By : Shakil Pathan | 29-Jun-2015
Hi,
In this blog, I am going to explain you about the bootstrap validator plugin.
It is a jQuery plugin to validate form fields and used with Bootstrap 3.
For validating the form data we just need to include bootstrapValidator.js file in our html code and need to do some configuration in our html and javascript code files.
Here are the bootstrap classes and code we need to configure in our html code:
In the above code I have just included some bootstrap classes and named the input boxes.
And here are the javascript configuration that need to do in our javascript file for validate those input boxes:
$(document).ready(function() {
$('#validateForm').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
username: {
message: 'The username is not valid.',
validators: {
notEmpty: {
message: 'The username is mandatory'
},
regexp: {
regexp: /^[a-zA-Z]+$/,
message: 'The username can only consist of alphabetics'
}
}
},
password: {
validators: {
notEmpty: {
message: 'The password is required and can\'t be empty'
}
}
}
}
})
})
In the above code I have done configuration for validate username and password. You can also validate more field like emails, identical password and confirm password, file validation like size and extension and many more.
For more information you can visit http://bootstrapvalidator.com.
Hope it helps!
Thanks
Shakil
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Shakil Pathan
Shakil is an experienced Groovy and Grails developer . He has also worked extensively on developing STB applications using NetGem .