bootstrap-validate 1.0.10

A simple Form Validation Utility for Bootstrap not depending on jQuery

DownloadStar on GitHub

Usage

bootstrap-validate is built with ease-of-use in mind. You don't need to be a regular ECMAScript® Spec Contributor to use this library!

The bootstrapValidate() function

This library exposes a single function:bootstrapValidate().

Currently, you can pass up to 3 Arguments:

Passing an Element

Passing an Element to bootstrap-validate is exactly the same as usingdocument.querySelector(), so you can pass a classbootstrapValidate('.myClass'), an idbootstrapValidate('#myId')or any other querybootstrapValidate('input[type="text"]').

Read more about document.querySelector.

About Rules and Options

Throughout the documentation around bootstrap-validate we make use of two (and only two) concepts: Rules and Options.

What is a Rule?

A rule is a condition to be met for your input element. If you wanted your visitor to enter an E-mail address, You would want to make use of the email rule.

bootstrapValidate('#input', 'email')

Of course, you can pass multiple rules.

Separate multiple rules with a |.

bootstrapValidate('#input', 'email|required'

But wait, there is Options!

The examples above would not work if you pasted them right into your Code. Every rule has to be supplied with at least one Option: The error text, which comes after all other options.

In the following, we will use the email rule, which does not have any options except from the obligatory error text.

Separate options with a :.

bootstrapValidate('#email', 'email:Enter a valid E-Mail!')

Options are the place to supply necessary rule parameters. For Instance, there is a min rule telling your user to fill in at least X characters. If you wanted to make that 5 characters, you would writebootstrapValidate('#input', 'min:5:Enter at least 5 Characters');

← InstallationAvailable Rules →