- Source:
Default tests.
Each test has at least three members.
Each test either returns a boolean or an object.
Each test has at least three members.
validate()
- the method which is called when testing a value.message
- the property that holds the default error message.expects
- the 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() → {Object}
- Source:
Checks if a value is a valid credit card.
Example
var rule = {
cc: true
};
approve.value('5105105105105100', rule);
Returns:
An object with various properties relating to the value's score.
- Type
- Object
(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. MDN |
(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
var rule = {
strength: {
min: 8,
bonus: 10
}
};
approve.value('some value', rule);
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});