bootstrap-validate 1.0.10

A simple Form Validation Utility for Bootstrap not depending on jQuery

DownloadStar on GitHub

Available Rules

Bootstrap Validate currently ships the following rules. Below you will find a description of every rule, its very own options and a usage example.

Are you missing a rule to validate your Bootstrap Forms?

We can surely help you on that one! Also, adding rules is super easy.

But before you need to get your hands dirty, file an Issue to get your rule added!

Issue

min

Require a given minimum character count.

Options

Available Options: 1

  • number: Number of minimum characters. Example: 5

Usage

bootstrapValidate('#input', 'min:5:Obligatory Error Text')

Source

function min(input, _min) {
    /**
     * @param min number: Number of minimum characters.
     * @description Require a given minimum character count.
     */
    return input.value.length >= parseInt(_min, 10);
  }

max

Maximum character count required.

Options

Available Options: 1

  • number: Number of maximum characters. Example: 5

Usage

bootstrapValidate('#input', 'max:5:Obligatory Error Text')

Source

function max(input, _max) {
    /**
     * @param max number: Number of maximum characters.
     * @description Maximum character count required.
     */
    return input.value.length <= parseInt(_max, 10);
  }

email

Require a valid E-Mail Address.

Options

Available Options: 0

You only need to pass an Error Text.

Usage

bootstrapValidate('#input', 'email:Obligatory Error Text')

Source

function email(input) {
    return (
      /**
       * @description Require a valid E-Mail Address.
       */
      new RegExp(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(input.value)
    );
  }

required

Require a field to be filled out.

Options

Available Options: 0

You only need to pass an Error Text.

Usage

bootstrapValidate('#input', 'required:Obligatory Error Text')

Source

function required(input) {
    return (
      /**
       * @description Require a field to be filled out.
       */
      input.value.length > 0
    );
  }

url

Require a valid URL.

Options

Available Options: 0

You only need to pass an Error Text.

Usage

bootstrapValidate('#input', 'url:Obligatory Error Text')

Source

function url(input) {
    return (
      /**
       * @description Require a valid URL.
       */
      new RegExp(/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i).test(input.value)
    );
  }

integer

Require a valid integer.

Options

Available Options: 0

You only need to pass an Error Text.

Usage

bootstrapValidate('#input', 'integer:Obligatory Error Text')

Source

function integer(input) {
    /**
     * @description Require a valid integer.
     */
    if (isNaN(input.value)) {
      return false;
    }
    var x = parseFloat(input.value);

    return (x | 0) === x; // eslint-disable-line no-bitwise
  }

numeric

Require a valid numeric input.

Options

Available Options: 0

You only need to pass an Error Text.

Usage

bootstrapValidate('#input', 'numeric:Obligatory Error Text')

Source

function numeric(input) {
    return (
      /**
       * @description Require a valid numeric input.
       */
      !isNaN(parseFloat(input.value)) && isFinite(input.value)
    );
  }

alphanum

Require alphanumeric input, e.g. 0-9 and a-Z.

Options

Available Options: 0

You only need to pass an Error Text.

Usage

bootstrapValidate('#input', 'alphanum:Obligatory Error Text')

Source

function alphanum(input) {
    return (
      /**
       * @description Require alphanumeric input, e.g. 0-9 and a-Z.
       */
      new RegExp(/^[a-z0-9]+$/i).test(input.value)
    );
  }

contains

Require the input to contain a given string.

Options

Available Options: 1

  • string: String to appear in the Input Element Example: Name

Usage

bootstrapValidate('#input', 'contains:Name:Obligatory Error Text')

Source

function contains(input, string) {
    /**
     * @param string string: String to appear in the Input Element
     * @description Require the input to contain a given string.
     */
    return input.value.indexOf(string) !== -1;
  }
← Usage