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 fieldObject Bean field metadata.
valuestring Date or datetime value as string.
Returns:
The invalid date/datetime or
undefinedif 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 fieldObject Bean field metadata.
emailsArray.<object> Bean field value which is an array of email objects.
Returns:
Array of duplicated email addresses or
undefinedif 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 fieldObject Bean field metadata.
emailsArray.<Object> Bean field value which is an array of email objects.
Returns:
Array of invalid email addresses or
undefinedif 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 fieldObject Bean field metadata.
valuestring Field value which is a number.
Returns:
Value that must be exceeded if the limit is not met and
undefinedif 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 fieldObject Bean field metadata.
valuestring Field value which is an integer.
modelObject Model.
Returns:
Compare field label if is invalid,
undefinedotherwise.- Type
- string
-
<static> isBefore(field, value, model)
-
Validates that the given date is before the date of another field.
Parameters:
Name Type Description fieldObject Bean field metadata.
valuestring Field value which is an integer.
modelObject Model.
Returns:
Compare field label if it is invalid and
undefinedotherwise.- Type
- string | undefined
-
<static> lessThan(field, value)
-
Validates a value to make sure it's less than a given value.
Parameters:
Name Type Description fieldObject Bean field metadata.
valuestring Field value which is a number.
Returns:
Value that
valuemust be less than if the limit is not met andundefinedif it is.- Type
- number | undefined
-
<static> maxLength(field, value)
-
Validates the maximum length of a given value.
Parameters:
Name Type Description fieldstring Bean field metadata.
valuestring | number Bean field value.
Returns:
Maximum length or
undefinedif the field is valid.- Type
- number | undefined
-
<static> maxValue(field, value)
-
Validates maximum integer values.
Parameters:
Name Type Description fieldObject Bean field metadata.
valuestring Field value which is a number.
Returns:
Value of the actual max if the limit is not met and
undefinedif it is.- Type
- number | undefined
-
<static> minLength(field, value)
-
Validates the minimum length of a given value.
Parameters:
Name Type Description fieldObject Bean field metadata.
valuestring Bean field value.
Returns:
Minimum length or
undefinedif the field is valid.- Type
- number | undefined
-
<static> minValue(field, value)
-
Validates minimum integer values.
Parameters:
Name Type Description fieldObject Bean field metadata.
valuestring Field value which is a number.
Returns:
Value of the actual min if the limit is not met and
undefinedif it is.- Type
- number | undefined
-
<static> number(field, value)
-
Validates numeric values.
Parameters:
Name Type Description fieldObject Bean field metadata.
valuestring field value which is an integer
Returns:
trueifvalueis invalid,undefinedotherwise.- 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 fieldObject Bean field metadata.
emailsArray.<Object> Bean field value which is an array of email objects.
Returns:
trueif there is no primary email set orundefinedif 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 fieldObject Bean field metadata.
valuestring Bean field value.
- Deprecated:
-
- Since 7.10