ValidationService Class
Provides a set of functions for common validations.
Constructor
ValidationService
()
Item Index
Methods
- isArray
- isBool static
- isDate static
- isEmail
- isEmpty static
- isFloat static
- isId static
- isIdStr static
- isInt static
- isNonEmptyStr
- isNum static
- isObject
- isSafeFileName
- isStr
- isUrl
- isVersionExpression
- isVersionNum
- validateArray deprecated
- validateEmail deprecated
- validateNonEmptyStr deprecated
- validateObject deprecated
- validateSafeFileName deprecated
- validateStr deprecated
- validateUrl deprecated
- validateVersionNum deprecated
Methods
isArray
-
value
-
[required=false]
Validates an array
Parameters:
-
value
Array -
[required=false]
Boolean optional
isBool
-
val
Validates that the value is a boolean.
Parameters:
-
val
The value under test
Returns:
TRUE if the value is valid, FALSE if not
isDate
-
val
-
[required=false]
Validates that the value is a date object
Parameters:
-
val
The value under test
-
[required=false]
Boolean optional
Returns:
TRUE if the value is valid, FALSE if not
isEmail
-
value
-
[required=false]
Validates an email address
Parameters:
-
value
String -
[required=false]
Boolean optional
isEmpty
-
val
Validates that the value is null, defined, an empty object, and empty array or an empty string.
Parameters:
-
val
The value under test
Returns:
TRUE if the value is valid, FALSE if not
isFloat
-
val
-
[required=false]
-
strict
Validates that the value is a float.
Parameters:
-
val
The value under test
-
[required=false]
Boolean optionalIndicates if the value is required. When FALSE, null will be an acceptable value.
-
strict
BooleanIndicates if the value must be a number rather than a string representing a number.
Returns:
TRUE if the value is valid, FALSE if not
isId
-
val
-
[required=false]
Checks to see if the value is a valid ID string or an instance of ObjectID.
Parameters:
-
val
String | ObjectIDThe value under test
-
[required=false]
Boolean optionalIndicates if the value is required. When FALSE, null will be an acceptable value.
Returns:
TRUE if the value is valid, FALSE if not
isIdStr
-
val
-
[required=false]
Checks to see if the value is a valid ID string
Parameters:
-
val
StringThe value under test
-
[required=false]
Boolean optionalIndicates if the value is required. When FALSE, null will be an acceptable value.
Returns:
TRUE if the value is valid, FALSE if not
isInt
-
val
-
[required=false]
-
strict
Validates that the value is an integer.
Parameters:
-
val
IntegerThe value under test
-
[required=false]
Boolean optionalIndicates if the value is required. When FALSE, null will be an acceptable value.
-
strict
BooleanIndicates if the value must be a number rather than a string representing a number.
Returns:
TRUE if the value is valid, FALSE if not
isNonEmptyStr
-
value
-
[required=false]
Validates a string is not empty
Parameters:
-
value
String -
[required=false]
Boolean optional
isNum
-
val
-
[required=false]
Validates that the value is a number.
Parameters:
-
val
The value under test
-
[required=false]
Boolean optionalIndicates if the value is required. When FALSE, null will be an acceptable value.
Returns:
TRUE if the value is valid, FALSE if not
isObject
-
value
-
[required=false]
Validates an object
Parameters:
-
value
Object -
[required=false]
Boolean optional
isSafeFileName
-
value
-
[required=false]
Validates a file name
Parameters:
-
value
String -
[required=false]
Boolean optional
isStr
-
value
-
[required=false]
Validates a string
Parameters:
-
value
String -
[required=false]
Boolean optional
isUrl
-
value
-
[required=false]
Validates an URL
Parameters:
-
value
String -
[required=false]
Boolean optional
isVersionExpression
-
expression
-
[required=false]
Validates a version expression
Parameters:
-
expression
String -
[required=false]
Boolean optional
isVersionNum
-
value
-
[required=false]
Validates a version number
Parameters:
-
value
String -
[required=false]
Boolean optional
validateArray
-
value
-
[required=false]
Validates an array
Parameters:
-
value
Array -
[required=false]
Boolean optional
validateEmail
-
value
-
[required=false]
Validates an email address
Parameters:
-
value
String -
[required=false]
Boolean optional
validateNonEmptyStr
-
value
-
[required=false]
Validates a string is not empty
Parameters:
-
value
String -
[required=false]
Boolean optional
validateObject
-
value
-
[required=false]
Validates an object
Parameters:
-
value
Object -
[required=false]
Boolean optional
validateSafeFileName
-
value
-
[required=false]
Validates a file name
Parameters:
-
value
String -
[required=false]
Boolean optional
validateStr
-
value
-
[required=false]
Validates a string
Parameters:
-
value
String -
[required=false]
Boolean optional
validateUrl
-
value
-
[required=false]
Validates an URL
Parameters:
-
value
String -
[required=false]
Boolean optional
validateVersionNum
-
value
-
[required=false]
Validates a version number
Parameters:
-
value
String -
[required=false]
Boolean optional
Properties
Pattern to validate a file name
Pattern to validate a semantic package version
A pattern to validate an email address
A pattern to validate a fully qualified URL
A pattern to validate a relative URL (no protocol, host, or port)