A simple Form Validation Utility for Bootstrap 3 and Bootstrap 4 for Humans.
| bootstrap-validate Version | Bootstrap Version | Documentation |
|---|---|---|
| v1 | Bootstrap 3 | v1 Download + Docs |
| v2 | Bootstrap 4 | v2 Download + Docs |
| v3 | Bootstrap 5 | Planned refactor |
Read the Documentation at bootstrap-validate.js.org.
$ npm i bootstrap-validateInclude the bootstrap-validate.js script:
<script defer src="https://cdn.jsdelivr.net/npm/bootstrap-validate@2.3.0/dist/bootstrap-validate.js"></script>We want the #name to be not longer than 30 characters!
<div class="form-group">
<label class="control-label">Enter a Name</label>
<input id="name">
</div>
<script>
bootstrapValidate('#name', 'max:30:Your name must not be longer than 30 characters');
</script>Validating an #email address couldn't be easier!
<div class="form-group">
<label for="email" class="control-label">Enter your E-Mail</label>
<input class="input" id="email">
</div>
<script>
bootstrapValidate('#email', 'email:Enter a valid email address');
</script>Validate before submit by keeping the returned handles:
const validators = [
bootstrapValidate('#email', 'required:Email required|email:Enter a valid email'),
bootstrapValidate('#password', 'required:Password required'),
];
document.querySelector('#account').addEventListener('submit', (event) => {
const isValid = validators.map((validator) => validator.validate()).every(Boolean);
if (!isValid) event.preventDefault();
});See the v2 Documentation on https://bootstrap-validate.js.org/v2/ to see all available validation features, examples, regex escaping, select/select2 usage, synchronous custom rules, and usage with module bundlers.
See the documentation examples for real-world usage.
You can find current Releases under Releases and older Releases for Bootstrap 3 and Bootstrap 4 in the Download Archive.
See CHANGELOG.
Validation Rules are at least unit-tested. Use npm test to spin up the test suites.
Licensed under the MIT License, see LICENSE.
