BootstrapValidator is the best jQuery plugin to validate form fields, designed to use with Bootstrap 3. It's developed with love by @nghuuphuoc.
The latest version, v0.4.5, is released on 2014-05-15
<form id="tryitForm" class="form-horizontal">
<div class="form-group">
<label class="col-md-3 control-label">Full name</label>
<div class="col-md-4">
<input type="text" class="form-control" name="firstName" />
</div>
<div class="col-md-4">
<input type="text" class="form-control" name="lastName" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Email address</label>
<div class="col-md-6">
<input type="text" class="form-control" name="email" />
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Gender</label>
<div class="col-md-6">
<div class="radio">
<label><input type="radio" name="gender" value="male" /> Male</label>
</div>
<div class="radio">
<label><input type="radio" name="gender" value="female" /> Female</label>
</div>
<div class="radio">
<label><input type="radio" name="gender" value="other" /> Other</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-3 col-md-8">
<button type="submit" class="btn btn-primary">Say hello</button>
</div>
</div>
</form>
<script>
$(document).ready(function() {
$('#tryitForm').bootstrapValidator({
fields: {
firstName: {
validators: {
notEmpty: {
message: 'The first name is required and cannot be empty'
}
}
},
lastName: {
validators: {
notEmpty: {
message: 'The last name is required and cannot be empty'
}
}
},
email: {
validators: {
notEmpty: {
message: 'The email address is required'
},
emailAddress: {
message: 'The input is not a valid email address'
}
}
},
gender: {
validators: {
notEmpty: {
message: 'The gender is required'
}
}
}
},
submitHandler: function(validator, form, submitButton) {
var fullName = [validator.getFieldElements('firstName').val(),
validator.getFieldElements('lastName').val()].join(' ');
$('#helloModal')
.find('.modal-title').html('Hello ' + fullName).end()
.modal();
}
});
});
</script>
data-bv-
min
, max
, pattern
, required
color
, email
, range
and url
name
or CSS selectorWe play nice with all of them!
The latest v0.4.5 version comes with following new features and fixes:
$.fn.bootstrapValidator.helpers.date
for validating a date, re-used in date
, id
, vat
validatorsthreshold
optionid
validatorseparator
option to the numeric
validatorisin
(International Securities Identification Number) validatorrtn
(Routing transit number) validatorcusip
(North American Securities) validatorsedol
(Stock Exchange Daily Official List) validatorzipCode
validator adds support for Italian, Dutch postcodescvv
validator should support spaces in credit card, thanks to @evilchilisubmitButtons
to [type="submit"]
to support input type="submit"
iban
validator does not work on IE8It is much better by the amazing developers