Demos

required

Tests the presence of a value. (Not empty or null)

@{{error}}

var rules = {
    title: 'Required',
    required: true
};
var result = approve.value('Some text...', rules);

email

Test for a valid email address.

{{error}}

var rules = {
    title: 'Email',
    email: true
};
var result = approve.value('Some text...', rules);

url

Test for a valid web address.

{{error}}

var rules = {
    title: 'Url',
    url: true
};
var result = approve.value('Some text...', rules);

cc

Test for a valid credit card number.

{{ccTest.result.scheme}} {{error}}

var rules = {
    title: 'Credit Card',
    cc: true
};
var result = approve.value('Some text...', rules);

alphaNumeric

Check if the value contains both alphabet characters and numbers.

{{error}}

var rules = {
    title: 'Alphanumeric',
    alphaNumeric: true
};
var result = approve.value('Some text...', rules);

alpha

Test for alphabet characters only.

{{error}}

var rules = {
    title: 'Alpha',
    alpha: true
};
var result = approve.value('Some text...', rules);

numeric

Test for numbers only.

{{error}}

var rules = {
    title: 'Numeric',
    numeric: true
};
var result = approve.value('Some text...', rules);

decimal

Test for a valid decimal.

{{error}}

var rules = {
    title: 'Decimal',
    decimal: true
};
var result = approve.value('Some text...', rules);

currency

Similar to decimal, but for currency values.

{{error}}

var rules = {
    title: 'Currency',
    currency: true
};
var result = approve.value('Some text...', rules);

ip

Test for a valid ipv4 or ipv6 address.

Supports CIDR notation.

{{error}}

var rules = {
    title: 'IP',
    ip: true
};
var result = approve.value('Some text...', rules);

min

Test for a minimum length of n characters.

{{error}}

var rules = {
    title: 'Min',
    min: 6
};
var result = approve.value('Some text...', rules);

max

Test for a maximum length of n characters.

{{error}}

var rules = {
    title: 'Max',
    max: 8
};
var result = approve.value('Some text...', rules);

range

Test for a minimum length of x and a maximum length of y characters.

{{error}}

var rules = {
    title: 'Range',
    range: {
        min: 6,
        max: 8
    }
};
var result = approve.value('Some text...', rules);

equal

Test for equality between two values.

{{error}}

var rules = {
    title: 'Password Confirmation',
    equal: {
        value: 'Some other text...',
        field: 'Password'
    }
};
var result = approve.value('Some text...', rules);

format

Test against a custom regular expression.

{{error}}

var rules = {
    title: 'Format',
    format: {
        regex: /^[a-z]+$/
    }
};
var result = approve.value('Some text...', rules);

time

Test for a valid string representing time in a 24 hour format (hh:mm:ss).

{{error}}

var rules = {
    title: 'Time',
    time: true
};
var result = approve.value('12:25:30', rules);

date

Test for a valid string representing a date (YYYY[/-]MM[/-]DD).

{{error}}

var rules = {
    title: 'Date',
    date: true
};
var result = approve.value('2016-10-01', rules);

truthy

Test for a truthy value ('Yes', 'true', '1', 'ok[ay]').

{{error}}

var rules = {
    title: 'Truthy',
    truthy: true
};
var result = approve.value('Yes', rules);

falsy

Test for a falsy value ('No', 'false', '0').

{{error}}

var rules = {
    title: 'Falsy',
    falsy: true
};
var result = approve.value('No', rules);

strength

Test for a strong password-like string using a 6 point scoring system.

{{error}}

var rules = {
    title: 'Password',
    strength: {
        min: 6,
        bonus: 10
    }
};
var result = approve.value('Some text...', rules);