tests

approve. tests

Source:
Default tests. Each test has at least three members A 'validate' method wich is called when testing a value, a 'message' property that holds the default error message and an 'expects' property that is either false if the test expects no parameters, or an array of strings representing the names of the expected parameters. Each test either returns a boolean or an object.

Methods

(inner) alpha()

Source:
Checks if a value contains only letters.
Example
approve.value('some value', {alpha: true});

(inner) alphaNumeric()

Source:
Checks if a value contains both letters and numbers.
Example
approve.value('some value', {alphaNumeric: true});

(inner) cc()

Source:
Checks if a value is a valid credit card number.
Example
approve.value('some value', {cc: true});

(inner) currency()

Source:
Similar to 'decimal', but for currency values.
Example
approve.value('some value', {currency: true});

(inner) decimal()

Source:
Checks if a value is a valid decimal.
Example
approve.value('some value', {decimal: true});

(inner) email()

Source:
Checks if a value is a valid email address.
Example
approve.value('some value', {email: true});

(inner) equal(field)

Source:
Checks if a value is the same as the value of another. This test gets the value from a DOM <input/> element.
Example
var rule = {
    equal: 'password'
};
approve.value('some value', rule);
Parameters:
Name Type Description
field string The id of the DOM <input/> element to test against.

(inner) format(regex)

Source:
Checks if a value passes a given regular expression.
Example
var rule = {
    format: /^[A-Za-z0-9]+$/i
};
approve.value('some value', rule);
Parameters:
Name Type Description
regex regexp The regular expression to test against.

(inner) ip()

Source:
Checks if a value is a valid ipv4 or ipv6 address.
Example
approve.value('some value', {ip: true});

(inner) max(max)

Source:
Checks if a value is a maximum of n characters.
Example
approve.value('some value', {max: 20});
Parameters:
Name Type Description
max integer The maximum allowed length.

(inner) min(min)

Source:
Checks if a value is a minimum of n characters.
Example
approve.value('some value', {min: 5});
Parameters:
Name Type Description
min integer The minimum allowed length.

(inner) numeric()

Source:
Checks if a value contains only numbers.
Example
approve.value('some value', {numeric: true});

(inner) range(min, max)

Source:
Checks if a value's length is between a minimum and maximum.
Example
var rule = {
    range: {
        min: 5,
        max: 20
    }
};
approve.value('some value', rule);
Parameters:
Name Type Description
min integer The minimum allowed length.
max integer The maximum allowed length.

(inner) required()

Source:
Checks if a value is present.
Example
approve.value('some value', {required: true});

(inner) strength() → {object}

Source:
Checks if a value is a strong password string.
Example
approve.value('some value', {srength: true});
Returns:
An object with various properties relating to the value's score.
Type
object

(inner) url()

Source:
Checks if a value is a valid web address.
Example
approve.value('some value', {url: true});