Quick reference for `checkit` validators
This article was originally published at https://gist.github.com/joepie91/cd107b3a566264b28a3494689d73e589.
Presence
- exists - The field must exist, and not be
undefined. - required - The field must exist, and not be
undefined,nullor an empty string. - empty - The field must be some kind of "empty". Things that are considered "empty" are as follows:
""(empty string)[](empty array){}(empty object)- Other falsey values
Character set
- alpha -
a-z,A-Z - alphaNumeric -
a-z,A-Z,0-9 - alphaUnderscore -
a-z,A-Z,0-9,_ - alphaDash -
a-z,A-Z,0-9,_,-
Value
- exactLength:
length- The value must have a length of exactlylength. - minLength:
length- The value must have a length of at leastlength. - maxLength:
length- The value must have a length of at mostlength. - contains:
needle- The value must contain the specifiedneedle(applies to both strings and arrays). - accepted - Must be a value that indicates agreement - varies by language (defaulting to
en):- en, fr, nl -
"yes","on","1",1,"true",true - es -
"yes","on","1",1,"true",true,"si" - ru -
"yes","on","1",1,"true",true,"да"
- en, fr, nl -
Value (numbers)
Note that "numbers" refers to both Number-type values, and strings containing numeric values!
- numeric - Must be a finite numeric value of some sort.
- integer - Must be an integer value (either positive or negative).
- natural - Must be a natural number (ie. an integer value of 0 or higher).
- naturalNonZero - Must be a natural number, but higher than 0 (ie. an integer value of 1 or higher).
- between:
min:max- The value must numerically be between theminandmaxvalues (exclusive). - range:
min:max- The value must numerically be within theminandmaxvalues (inclusive). - lessThan:
maxValue- The value must numerically be less than the specifiedmaxValue(exclusive). - lessThanEqualTo:
maxValue- The value must numerically be less than or equal to the specifiedmaxValue(inclusive). - greaterThan:
minValue- The value must numerically be greater than the specifiedminValue(exclusive). - greaterThanEqualTo:
minValue- The value must numerically be greater than or equal to the specifiedminValue(inclusive).
Relations to other fields
- matchesField:
field- The value in this field must equal the value in the specified otherfield. - different:
field- The value in this field must not equal the value in the specified otherfield.
JavaScript types
- NaN - Must be
NaN. - null - Must be
null - string - Must be a
String. - number - Must be a
Number. - array - Must be an
Array. - plainObject - Must be a plain
object(ie. object literal). - date - Must be a
Dateobject. - function - Must be a
Function. - regExp - Must be a
RegExpobject. - arguments - Must be an
argumentsobject.
Format
- email - Must be a validly formatted e-mail address.
- luhn - Must be a validly formatted creditcard number (according to a Luhn regular expression).
- url - Must be a validly formatted URL.
- ipv4 - Must be a validly formatted IPv4 address.
- ipv6 - Must be a validly formatted IPv6 address.
- uuid - Must be a validly formatted UUID.
- base64 - Must be a validly formatted base64 string.
No Comments