A simple Form Validation Utility for Bootstrap which does not depend on jQuery.
- Include the bootstrap-validate.js script:
<script src="bootstrap-validate.js"></script>
- Setup Validation for your Input Elements:
Imagine the following HTML:
<div class="form-group">
<label class="control-label">Enter a Name</label>
<input id="name">
</div>
Now you want a Name to be at max 30 characters long and add the following:
<script>
bootstrapValidate(
document.getElementById('name'),
'max:30:Your name must not be longer than 30 characters'
);
</script>
the first argument of bootstrapValidate is your element to be validated. The second argument is a string of rules, whereas:
- Multiple Rules are separated by an amount sign |.
- A Rule starts with its name, see Available Rules.
- The following arguments are the required rule parameters:
max
only requires a number. - The last argument is the string to be displayed when validation fails.
- Single Rule Options are separated by a colon :.
min:1:Enter a character|max:2:Enter at max 2 characters
- Input Elements
min
: (number) Minimal Number of Charactersmax
: (number) Maximal Number of Characters
Adding Rules is super easy! Have a look at src/rules
. and How to Contribute.
You can download the latest Release here: https://cdn.rawgit.com/PascaleBeier/bootstrap-validate/1.0.0/dist/bootstrap-validate.js.
npm i bootstrap-validate
bower install bootstrap-validate --save
Contributing is easy as pie.
- Fork this Repository
- run
npm i
inside of the repository - run
npm dev
to view changes - run
npm build
to build for production - Commit your changes, push these to your fork and submit a PR
(You can use or create new files below examples
until I got tests ready)
You will be notified of styling errors - also you can npm check-style
and npm fix-style
respectively to check or fix
code styling.
Licensed under the MIT License, see LICENSE.