new Validators()
A hash of validators. Each validator function must return an error
definition if validation fails and undefined
if it succeeds.
Error definitions can be primitives value such as max length or an array, such as a range's lower and upper limits. Validator functions accept field metadata and the value to be validated.
Methods
-
<static> datetime(field, value)
-
Validates that a given value is a real date or datetime.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Date or datetime value as string.
Returns:
The invalid date/datetime or
undefined
if it is a valid date.- Type
- string | undefined
-
<static> duplicateEmail(field, emails)
-
Validates that a given email array has no duplicate email addresses.
Parameters:
Name Type Description field
Object Bean field metadata.
emails
Array.<object> Bean field value which is an array of email objects.
Returns:
Array of duplicated email addresses or
undefined
if there are no duplicates.- Type
- Array.<string> | undefined
-
<static> email(field, emails)
-
Validates that a given value contains only valid email address. Note that it is impossible to do full validation of email addresses in JavaScript.
Parameters:
Name Type Description field
Object Bean field metadata.
emails
Array.<Object> Bean field value which is an array of email objects.
Returns:
Array of invalid email addresses or
undefined
if the addresses are all valid.- Type
- Array.<string> | undefined
-
<static> greaterThan(field, value)
-
Validates a value to make sure it's larger than a given value.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Field value which is a number.
Returns:
Value that must be exceeded if the limit is not met and
undefined
if it is.- Type
- number | undefined
-
<static> isAfter(field, value, model)
-
Validates that the given date is after the date of another field.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Field value which is an integer.
model
Object Model.
Returns:
Compare field label if is invalid,
undefined
otherwise.- Type
- string
-
<static> isBefore(field, value, model)
-
Validates that the given date is before the date of another field.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Field value which is an integer.
model
Object Model.
Returns:
Compare field label if it is invalid and
undefined
otherwise.- Type
- string | undefined
-
<static> lessThan(field, value)
-
Validates a value to make sure it's less than a given value.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Field value which is a number.
Returns:
Value that
value
must be less than if the limit is not met andundefined
if it is.- Type
- number | undefined
-
<static> maxLength(field, value)
-
Validates the maximum length of a given value.
Parameters:
Name Type Description field
string Bean field metadata.
value
string | number Bean field value.
Returns:
Maximum length or
undefined
if the field is valid.- Type
- number | undefined
-
<static> maxValue(field, value)
-
Validates maximum integer values.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Field value which is a number.
Returns:
Value of the actual max if the limit is not met and
undefined
if it is.- Type
- number | undefined
-
<static> minLength(field, value)
-
Validates the minimum length of a given value.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Bean field value.
Returns:
Minimum length or
undefined
if the field is valid.- Type
- number | undefined
-
<static> minValue(field, value)
-
Validates minimum integer values.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Field value which is a number.
Returns:
Value of the actual min if the limit is not met and
undefined
if it is.- Type
- number | undefined
-
<static> number(field, value)
-
Validates numeric values.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string field value which is an integer
Returns:
true
ifvalue
is invalid,undefined
otherwise.- Type
- boolean | undefined
-
<static> primaryEmail(field, emails)
-
Validates that a given email array has at least one email set as the primary email.
Parameters:
Name Type Description field
Object Bean field metadata.
emails
Array.<Object> Bean field value which is an array of email objects.
Returns:
true
if there is no primary email set orundefined
if at least one of the emails is the primary email.- Type
- boolean | undefined
-
<static> url(field, value)
-
Validates that a given value is a valid URL. Note that is impossible to do full validation of URLs in JavaScript.
This function has been a no-op since 6.7. Do NOT use it.
Parameters:
Name Type Description field
Object Bean field metadata.
value
string Bean field value.
- Deprecated:
-
- Since 7.10