Skip to content
This repository has been archived by the owner on Dec 21, 2017. It is now read-only.

Assertions

fogine edited this page Mar 3, 2017 · 7 revisions
name argument default description
$is one of the Data type values Checks whether validated entity is of type specified. Eg.: {username: {$is: String}}
$isAfter Date / String Check if a string is a date that's after the specified date (defaults to now). Eg.: {created_at: {$isAfter: "2011-08-04"}}
$isAlpha one of the Locales "en-US" Checks if the string contains only letters (a-zA-Z). Eg.: {username: {$isAlpha: 'en-US'}}
$isAlphanumeric one of the Locales "en-US" Checks if the string contains only letters and numbers.
$isAscii Checks if the string contains ASCII chars only. Eg.: {username: {$isAscii: null}}
$isBase64 Checks if a string is base64 encoded. Eg.: {thumbnail-data: {$isBase64: null}}
$isBefore Date / String Checks if the string is a date that's before the specified date. Eg.: {created_at: {$isBefore: new Date}}
$isBoolean Checks if a string is a boolean. Eg.: {banned: {$isBoolean: null}}
$hasByteLength MinMaxBoundariesOptionsObject {min:0} Checks if the string's length (in bytes) falls in a range.
$isCreditCard check if the string is a credit card
$isCurrency CurrencyOptionsObject see here check if the string is a valid currency amount
$isDataURI check if the string is a data uri format.
$isDate check if the string is a date.
$isDecimal check if the string represents a decimal number, such as 0.1, .3, 1.1, 1.00003, 4.0, etc.
$isDivisibleBy Number check if the string is a number that's divisible by another. Eg.: {amount: {$isDivisibleBy: 2}}
$isEmail EmailOptionsObject see here check if the string is an email
$isFQDN FQDNOptionsObject see here check if the string is a fully qualified domain name (e.g. domain.com)
$isFloat MinMaxBoundariesOptionsObject check if the string is a float.
$isFullWidth check if the string contains any full-width chars.
$isHalfWidth check if the string contains any half-width chars.
$isHexColor check if the string is a hexadecimal color.
$isHexadecimal check if the string is a hexadecimal number.
$isIP Integer - either 4 or 6 check if the string is an IP (version 4 or 6).
$isISBN Integer - either 10 or 13 check if the string is an ISIN (version 10 or 13).
$isInt MinMaxBoundariesOptionsObject check if the string is an integer
$isJSON check if the string is valid JSON (note: uses JSON.parse).
$hasLengthOf MinMaxBoundariesOptionsObject {min: 0} check if the string's or array's length falls in a range
$isNumeric check if the string contains only numbers
$isURL UrlOptionsObject check if the string is an URL
$isUUID Integer - one of 3, 4 or 5 check if the string is a UUID (version 3, 4 or 5).
$matches Regexp check if string matches the pattern. Eg.: {username: {$matches: /^[A-B]+$/ }}
$isEmpty check if the value is either undefined or null
$gt Number check if the value is greater than specified number. Eg.: {age: {$gt: 18}}. You can also refer to other data property: {age: {$gt: {$ref: "child.age"}}}
$gte Number check if the value is greater than or equal to specified number. Eg.: {age: {$gte: 18}} . You can also refer to other data property: {age: {$gte: {$ref: "child.age"}}}
$lt Number check if the value is lower than specified number. Eg.: {age: {$lt: 18}} . You can also refer to other data property: {age: {$lt: {$ref: "child.age"}}}
$lte Number check if the value is lower than or equal to specified number. Eg.: {age: {$lte: 18}} . You can also refer to other data property: {age: {$lte: {$ref: "child.age"}}}
$eq Number check if the value is equal to specified number. Eg.: {age: {$eq: 18}} . You can also refer to other data property: {age: {$eq: {$ref: "child.age"}}}
$ne Number check if the value is NOT equal to specified number. Eg.: {age: {$ne: 18}}. You can also refer to other data property: {age: {$ne: {$ref: "child.age"}}}
$between Array check if the value is number between defined min and max boundaries. (Including defined min, max values). Eg.: {age: {$between: [18, 50]}}
$notBetween Array check if the value is number outside of defined min and max range. (Including defined min, max values). Eg.: {age: {$notBetween: [0, 17]}}
$like String / LikeFilterObject check if the value matches defined sql-LIKE pattern. Eg.: {username: {$like: "%happie%"}} OR: Eg.: {username: {$like: {$any: ["%happie%", "%cat%"]}}}
$notLike String / LikeFilterObject negated $like version
$iLike String / LikeFilterObject case insensetive $like version
$notILike String / LikeFilterObject negated $iLike version
$in Array / Object check if value is one of values in provided array or one of the index values in provided hash table
$notIn Array / Object negated $in version

Locales

'ar' 'ar-AE' 'ar-BH' 'ar-DZ' 'ar-EG' 'ar-IQ' 'ar-JO' 'ar-KW' 'pl-PL'
'ar-LB' 'ar-LY' 'ar-MA' 'ar-QA' 'ar-QM' 'ar-SA' 'ar-SD' 'ar-SY' 'pt-PT'
'ar-TN' 'ar-YE' 'cs-CZ' 'de-DE' 'en-AU' 'en-GB' 'en-HK' 'en-IN' 'ru-RU'
'en-NZ' 'en-US' 'en-ZA' 'en-ZM' 'es-ES' 'fr-FR' 'hu-HU' 'nl-NL' 'tr-TR'

$is - Data type list

Object "Object" Array "Array" String "String" Number "Number" null

MinMaxBoundariesOptionsObject

property type
min Number
max Number

CurrencyOptionsObject

property type default
symbol String "$"
require_symbol Boolean false
allow_space_after_symbol Boolean false
symbol_after_digits Boolean false
allow_negatives Boolean true
parens_for_negatives Boolean false
negative_sign_before_digits Boolean false
negative_sign_after_digits Boolean false
allow_negative_sign_placeholder Boolean false
thousands_separater String ","
decimal_separator String "."
allow_space_after_digits Boolean false

EmailOptionsObject

property type default
allow_display_name Boolean false
allow_utf8_local_part Boolean true
require_tld Boolean true

If allow_display_name is set to true, the validator will also match Display Name <email-address>. If allow_utf8_local_part is set to false, the validator will not allow any non-English UTF8 character in email address' local part. If require_tld is set to false, e-mail addresses without having TLD in their domain will also be matched.

FQDNOptionsObject

property type default
require_tld Boolean true
allow_underscores Boolean false
allow_trailing_dot Boolean false

UrlOptionsObject

property type default
protocols Array ['http', 'https', 'ftp']
require_tld Boolean true
require_protocol Boolean false
require_valid_protocol Boolean true
allow_underscores Boolean false
host_whitelist Boolean false
host_blacklist Boolean false
allow_trailing_dot Boolean false
allow_protocol_relative_urls Boolean false

LikeFilterObject

property type
$any Array

==========================================================================

NOTE: The assertions mentioned in the following list use chriso validator for data validation internaly: $isAfter, $isAlpha, $isAlphanumeric, $isAscii, $isBase64, $isBefore, $isBoolean, $hasByteLength, $isCreditCard, $isCurrency, $isDataURI, $isDate, $isDecimal, $isDivisibleBy, $isEmail, $isFQDN, $isFloat, $isFullWidth, $isHalfWidth, $isHexColor, $isHexadecimal, $isIP, $isISBN, $isInt, $isJSON, $isNumeric, $isURL, $isUUID, $matches