pkeg / bootstrap-validate

A simple Form Validation Utility for Bootstrap which does not depend on jQuery.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bootstrap-validate

A simple Form Validation Utility for Bootstrap which does not depend on jQuery.

Demo

Usage

  1. Include the bootstrap-validate.js script:
<script src="bootstrap-validate.js"></script>
  1. 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>

API

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

Available Rules

  • Input Elements
    • min: (number) Minimal Number of Characters
    • max: (number) Maximal Number of Characters

Adding Rules is super easy! Have a look at src/rules. and How to Contribute.

Download

Manually

You can download the latest Release here: https://cdn.rawgit.com/PascaleBeier/bootstrap-validate/1.0.0/dist/bootstrap-validate.js.

npm

npm i bootstrap-validate

bower

bower install bootstrap-validate --save

Contributing

Contributing is easy as pie.

  1. Fork this Repository
  2. run npm i inside of the repository
  3. run npm dev to view changes
  4. run npm build to build for production
  5. 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.

License

Licensed under the MIT License, see LICENSE.

About

A simple Form Validation Utility for Bootstrap which does not depend on jQuery.

License:MIT License


Languages

Language:JavaScript 100.0%