README
sog-validator
Data validation engine.
The power library which provides the best way to validate any type of data.
Navigation
Installation and Usage
Server-side usage
Install the library with npm install sog-validator
No ES6
var sogv = require('sog-validator');
var validationEngine = new sogv.Application({
lang: 'en'
});
var form = validationEngine.make({
first_name: 'Leo',
last_lame: 'Lane',
email: 'leo.lane38@example.com',
birthday: '1977-03-07',
creditCard: '4111111111111111',
ip: '8.8.8.8',
locale: 'cy_GB',
country: 'US',
language: 'en_gb',
homepage: 'https://github.com//slaveofgod/sog-validator'
}, {
first_name: 'required|string|length:2,50',
last_lame: 'required|string|length:2,50',
email: 'required|email',
birthday: 'required|date',
creditCard: 'required|string|card-scheme:VISA;MASTERCARD',
ip: 'required|string|ip',
locale: 'required|string|locale',
country: 'required|string|country',
language: 'required|string|language',
homepage: 'required|string|url'
});
if (false === form.isValid()) {
if (false === form.get('name').isValid()) {
form.get('name').errors().first();
}
// ...
}
ES6
import sogv from 'sog-validator';
Client-side usage
The library can be loaded either as a standalone script.
<script type="text/javascript" src="node_modules/moment/min/moment-with-locales.js"></script>
<script type="text/javascript" src="node_modules/moment-timezone/builds/moment-timezone-with-data.js"></script>
<script type="text/javascript" src="build/output/sog-validator.min.js"></script>
<script type="text/javascript">
var validationEngine = new sogv.Application({
lang: 'en'
});
var form = validationEngine.make({
first_name: 'Leo',
last_lame: 'Lane',
email: 'leo.lane38@example.com',
birthday: '1977-03-07',
creditCard: '4111111111111111',
ip: '8.8.8.8',
locale: 'cy_GB',
country: 'US',
language: 'en_gb',
homepage: 'https://github.com//slaveofgod/sog-validator'
}, {
first_name: 'required|string|length:2,50',
last_lame: 'required|string|length:2,50',
email: 'required|email',
birthday: 'required|date',
creditCard: 'required|string|card-scheme:VISA;MASTERCARD',
ip: 'required|string|ip',
locale: 'required|string|locale',
country: 'required|string|country',
language: 'required|string|language',
homepage: 'required|string|url'
});
if (false === form.isValid()) {
if (false === form.get('name').isValid()) {
form.get('name').errors().first();
}
// ...
}
</script>
Single usage
<script type="text/javascript" src="node_modules/moment/min/moment-with-locales.js"></script>
<script type="text/javascript" src="node_modules/moment-timezone/builds/moment-timezone-with-data.js"></script>
<script type="text/javascript" src="build/output/sog-validator.min.js"></script>
<script type="text/javascript">
// Validation status only
if (false === sogv.isValid('leo.lane38@example.com', 'required|email')) {
// do something with invalid data
}
// Validation status and error message (returns message if data invalid or null if valid)
var message = sogv.isValidWithErrorMessage('leo.lane38@example.com', 'required|email');
if (null !== message) {
// do something with invalid data
}
</script>
Available Validation Rules
Below is a list of all available validation rules and their function:
Basic Constraints
These are the basic constraints: use them to assert very basic things about the value of properties or the return value of methods on your object.
- Accepted - The field under validation must be
yes
,on
,1
, ortrue
. - Not Blank - Validates that a value is
not blank
. - Blank - Validates that a value is blank.
- Not Null - Validates that a value is not strictly equal to
null
. - Is Null - Validates that a value is exactly equal to
null
. - Is True - Validates that a value is true.
- Is False - Validates that a value is false.
- Alpha Dash - The field under validation may have alpha-numeric characters, as well as dashes and underscores.
- Array - The field under validation must be an array.
- Boolean - The field under validation must be able to be cast as a boolean.
- Callable - Verify that the contents of a variable can be called as a function.
- Float - The field under validation must be a float.
- Double - The field under validation must be a double.
- Integer - The field under validation must be an integer.
- Iterable - Verify that the contents of a variable is an iterable value.
- Null - The field under validation must be a NULL.
- Numeric - The field under validation must be a number or a numeric string.
- Object - The field under validation must be an object.
- Real - Finds whether the type of a variable is real.
- Scalar - Finds whether a variable is a scalar.
- String - The field under validation must be a string.
- Alnum - Check for alphanumeric character(s).
- Alpha - Check for alphabetic character(s).
- Cntrl - Check for control character(s).
- Digit - Check for numeric character(s).
- Graph - Check for any printable character(s) except space.
- Lower - Check for lowercase character(s).
- Print - Check for printable character(s).
- Punct - Check for any printable character which is not whitespace or an alphanumeric character.
- Space - Check for whitespace character(s).
- Upper - Check for uppercase character(s).
- Xdigit - Check for character(s) representing a hexadecimal digit.
String Constraints
- Email - Validates that a value is a valid email address.
- Length - Validates that a given string length is between some
minimum
andmaximum
value. - Url - Validates that a value is a valid URL string.
- Regular Expression - Validates that a value matches a regular expression.
- Ip - Validates that a value is a valid IP address.
- IPv4 - The field under validation must be an
IPv4
address. - IPv6 - The field under validation must be an
IPv6
address. - Json - Validates that a value has valid
JSON
syntax. - Uuid - The field under validation must be a valid RFC 4122 (version 1, 3, 4, or 5) universally unique identifier (UUID).
- Ends With - The field under validation must end with one of the given values.
- Starts With - The field under validation must start with one of the given values.
- Contains - The field under validation must contains the given substring.
Comparison Constraints
- Equal To - Validates that a value is equal to another value, defined in the options.
- Not Equal To - Validates that a value is not equal to another value, defined in the options.
- Identical To - Validates that a value is identical to another value, defined in the options.
- Not Identical To - Validates that a value is not identical to another value, defined in the options.
- Less Than - Validates that a value is less than another value, defined in the options.
- Less Than Or Equal - Validates that a value is less than or equal to another value, defined in the options.
- Greater Than - Validates that a value is greater than another value, defined in the options.
- Greater Than Or Equal - Validates that a value is greater than or equal to another value, defined in the options.
- Range - Validates that a given number or Date object is between some
minimum
andmaximum
. - Between - The field under validation must have a size between the given
min
andmax
. - Digits Between - The field under validation must be
numeric
and must have a length between the givenmin
andmax
. - Divisible By - Validates that a value is divisible by another value, defined in the options.
- Unique - Validates that all the elements of the given collection are
unique
(none of them is present more than once). - Digits - The field under validation must be
numeric
and must have an exactlength
of value. - Distinct - When working with
arrays
, the field under validation must not have any duplicate values. - Size - The field under validation must have a size matching the given value.
- After (Date) - The field under validation must be a value after a given date.
- After Or Equal (Date) - The field under validation must be a value after or equal to the given date.
- Before (Date) - The field under validation must be a value before a given date.
- Before Or Equal (Date) - The field under validation must be a value before or equal to the given date.
- Date Equals - The field under validation must be
equal
to the givendate
.
Number Constraints
- Positive - Validates that a value is a
positive
number. - Positive Or Zero - Validates that a value is a
positive
number or equal tozero
. - Negativeaaa - Validates that a value is a
negative
number. - Negative Or Zero - Validates that a value is a
negative
number or equal tozero
.
Date Constraints
- Date - Validates that a value is a valid
date
, meaning a string (or an object that can be cast into a string) that follows a validYYYY-MM-DD
format. - Date Time - Validates that a value is a valid "datetime", meaning a string (or an object that can be cast into a string) that follows a specific format.
- Date Format - Validates that a value is a valid "datetime", meaning a string (or an object that can be cast into a string) that follows a specific format.
- Time - Validates that a value is a valid
time
, meaning a string (or an object that can be cast into a string) that follows a validHH:mm:ss
format. - Timezone - Validates that a value is a valid timezone identifier (e.g.
Europe/Paris
).
Choice Constraints
- Choice - This constraint is used to ensure that the given value is one of a given set of valid choices.
- Not In - The field under validation must not be included in the given list of values.
- In - The field under validation must be included in the given list of values.
- Language - Validates that a value is a valid language Unicode language identifier (e.g.
fr
orar-dz
). - Locale - Validates that a value is a valid locale.
- Country - Validates that a value is a valid 3166-1 alpha-2
country code
.
File Constraints
Financial and other Number Constraints
- Bic - This constraint is used to ensure that a value has the proper format of a Business Identifier Code (BIC).
- Card Scheme - This constraint ensures that a credit card number is valid for a given credit card company.
- Currency - Validates that a value is a valid 3-letter ISO 4217
currency
name. - Luhn - This constraint is used to ensure that a
credit card
number passes the Luhn algorithm. - Iban - This constraint is used to ensure that a bank account number has the proper format of an International Bank Account Number (IBAN).
- Isbn - This constraint validates that an International Standard Book Number (ISBN) is either a valid
ISBN-10
or a validISBN-13
. - Issn - Validates that a value is a valid International Standard Serial Number (ISSN).
Other Constraints
- Count - Validates that a given collection's (i.e. an array or an object that implements Countable) element
count
isbetween
someminimum
andmaximum
value. - Any - Validates that a value is valid at least for one of the rule.
Validation Rules
Accepted
aliases: accepted
The field under validation must be yes
, on
, 1
, or true
. This is useful for validating "Terms of Service" acceptance.
Not Blank
aliases: not-blank
, not-empty
, filled
Validates that a value is not blank
- meaning not equal to a blank string, a blank array, false or null (null behavior is configurable). The field under validation must not be empty when it is present.
Blank
aliases: blank
, empty
Validates that a value is blank - meaning equal to an empty string
or null
.
Not Null
aliases: not-null
, required
, present
Validates that a value is not strictly equal to null
.
Is Null
aliases: is-null
, nullable
Validates that a value is exactly equal to null
.
Is True
aliases: is-true
, true
Validates that a value is true. Specifically, this checks if the value is exactly true
, exactly the integer 1
, or exactly the string "1
".
Is False
aliases: is-false
, false
Validates that a value is false. Specifically, this checks to see if the value is exactly false, exactly the integer 0, or exactly the string "0".
Alpha Dash
aliases: alpha_dash
, alpha-dash
The field under validation may have alpha-numeric characters, as well as dashes and underscores.
Array
aliases: array
, arr
The field under validation must be an array.
Boolean
aliases: boolean
, bool
The field under validation must be able to be cast as a boolean. Accepted input are true, false, 1, 0, "1", and "0".
Callable
aliases: callable
Verify that the contents of a variable can be called as a function.
Float
aliases: float
The field under validation must be a float.
Double
aliases: double
The field under validation must be a double.
Integer
aliases: int
, integer
The field under validation must be an integer.
Iterable
aliases: iterable
Verify that the contents of a variable is an iterable value.
Null
aliases: null
The field under validation must be a NULL.
Numeric
aliases: numeric
, num
The field under validation must be a number or a numeric string.
Object
aliases: object
The field under validation must be an object.
Real
aliases: real
Finds whether the type of a variable is real.
Scalar
aliases: scalar
Finds whether a variable is a scalar. Scalar variables are those containing an integer, float, string or boolean.
String
aliases: string
, str
The field under validation must be a string.
Alnum
aliases: alnum
, alpha-num
, alpha_num
Check for alphanumeric character(s).
Alpha
aliases: alpha
Check for alphabetic character(s).
Cntrl
aliases: cntrl
Check for control character(s).
Digit
aliases: digit
Check for numeric character(s).
Graph
aliases: graph
Check for any printable character(s) except space.
Lower
aliases: lower
Check for lowercase character(s).
aliases: print
Check for printable character(s).
Punct
aliases: punct
Check for any printable character which is not whitespace or an alphanumeric character.
Space
aliases: space
Check for whitespace character(s).
Upper
aliases: upper
Check for uppercase character(s).
Xdigit
aliases: xdigit
Check for character(s) representing a hexadecimal digit.
aliases: email
usage: email:mode
available modes:
loose
- A simple regular expression. Allows all values with an "@
" symbol in, and a ".
" in the second host part of the email address.html5
- This matches the pattern used for theHTML5
email input element.
Validates that a value is a valid email address.
Length
aliases: length
, len
usage: length:min,max
Validates that a given string length is between some minimum
and maximum
value.
Url
aliases: url
Validates that a value is a valid URL string.
Regular Expression
aliases: regex
, regexp
usage: regex:pattern,match
options:
pattern
- This required option is the regular expression pattern that the input will be matched against.match
- Iftrue
(or not set), this validator will pass if the given string matches the given pattern regular expression. However, when this option is set tofalse
, the opposite will occur: validation will pass only if the given string does not match the pattern regular expression. Default:true
.
Validates that a value matches a regular expression.
Ip
aliases: ip
Validates that a value is a valid IP address.
IPv4
aliases: ipv4
The field under validation must be an IPv4
address.
IPv6
aliases: ipv6
The field under validation must be an IPv6
address.
Json
aliases: json
Validates that a value has valid JSON
syntax.
Uuid
aliases: uuid
usage: uuid:versions
options:
versions
- This is optional parameter. This option can be used to only allow specific UUID versions. Valid versions are 1 - 5. Default: [1, 2, 3, 4, 5].
The field under validation must be a valid RFC 4122 (version 1, 3, 4, or 5) universally unique identifier (UUID).
Ends With
aliases: ends_with
, ends-with
, ends
usage: ends-with:foo;bar;...
options:
ends
- The option is required. The list of ends. One of the "end
" needs to be the end of the passed value.
The field under validation must end with one of the given values.
Starts With
aliases: starts_with
, starts-with
, starts
usage: starts_with:foo;bar;...
options:
starts
- The option is required. The list of starts. One of the "start
" needs to be the end of the passed value.
The field under validation must start with one of the given values.
Contains
aliases: contains
usage: contains:value
options:
value
- The option is required. The substring.
The field under validation must contains the given substring.
Equal To
aliases: equal-to
, equal
, same
, et
usage: equal-to:value
options:
value
- This option is required. It defines the value to compare to. It can be astring
,number
orobject
.
Validates that a value is equal to another value, defined in the options. This constraint compares using ==
, so 3
and "3
" are considered equal.
Not Equal To
aliases: not-equal-to
, not-equal
, net
usage: not-equal-to:value
options:
value
- This option is required. It defines the value to compare to. It can be astring
,number
orobject
.
Validates that a value is not equal to another value, defined in the options. This constraint compares using !=
, so 3
and "3
" are considered equal.
Identical To
aliases: identical-to
, identical
, it
usage: identical-to:value
options:
value
- This option is required. It defines the value to compare to. It can be astring
,number
orobject
.
Validates that a value is identical to another value, defined in the options. This constraint compares using ===
, so 3
and "3
" are not considered equal.
Not Identical To
aliases: not-identical-to
, not-identical
, nit
usage: not-identical-to:value
options:
value
- This option is required. It defines the value to compare to. It can be astring
,number
orobject
.
Validates that a value is not identical to another value, defined in the options. This constraint compares using !==
, so 3
and "3
" are considered not equal.
Less Than
aliases: less_than
, less-than
, less
usage: less_than:value
options:
value
- This option is required. It defines the value to compare to. It can be astring
,number
ordate object
.
Validates that a value is less than another value, defined in the options.
Less Than Or Equal
aliases: less_than_or_equal
, less-than-or-equal
, max
usage: less_than_or_equal:value
options:
value
- This option is required. It defines the value to compare to. It can be astring
,number
ordate object
.
Validates that a value is less than or equal to another value, defined in the options.
Greater Than
aliases: greater_than
, greater-than
, greater
usage: greater_than:value
options:
value
- This option is required. It defines the value to compare to. It can be astring
,number
ordate object
.
Validates that a value is greater than another value, defined in the options.
Greater Than Or Equal
aliases: greater_than_or_equal
, greater-than-or-equal
, min
usage: greater_than_or_equal:value
options:
value
- This option is required. It defines the value to compare to. It can be astring
,number
ordate object
.
Validates that a value is greater than or equal to another value, defined in the options.
Range
aliases: range
usage: range:min,max
Validates that a given number or Date object is between some minimum
and maximum
.
Between
aliases: between
usage: between:min,max
The field under validation must have a size between the given min
and max
. Strings
, numerics
, arrays
and dates
are evaluated in the same fashion as the size rule.
Digits Between
aliases: digits_between
, digits-between
usage: digits_between:min,max
The field under validation must be numeric
and must have a length between the given min
and max
.
Divisible By
aliases: divisible-by
usage: divisible-by:value
options:
value
- This option is required. It defines the value to compare to. It can be anumber
ordate object
.
Validates that a value is divisible by another value, defined in the options.
Unique
aliases: unique
Validates that all the elements of the given collection are unique
(none of them is present more than once). Elements are compared strictly, so '7
' and 7
are considered different elements (a string and an integer, respectively). It can be a string
or array
.
Digits
aliases: digits
usage: digits:length
options:
length
- This option is required. It defines the exact count of digits.
The field under validation must be numeric
and must have an exact length
of value.
Distinct
aliases: distinct
When working with arrays
, the field under validation must not have any duplicate values.
Size
aliases: size
usage: size:value
options:
value
- This option is required. It defines the value to compare to.
The field under validation must have a size matching the given value. For string
data, value corresponds to the number of characters. For numeric
data, value corresponds to a given integer value. For an array
, size corresponds to the count of the array.
After (Date)
aliases: after
usage: after:value
options:
value
- This option is required. It defines the value to compare to. The data type could bestring
,number
ordate
.
The field under validation must be a value after a given date.
After Or Equal (Date)
aliases: after_or_equal
, after-or-equal
, aoe
usage: after_or_equal:value
options:
value
- This option is required. It defines the value to compare to. The data type could bestring
,number
ordate
.
The field under validation must be a value after or equal to the given date.
Before (Date)
aliases: before
usage: before:value
options:
value
- This option is required. It defines the value to compare to. The data type could bestring
,number
ordate
.
The field under validation must be a value before a given date.
Before Or Equal (Date)
aliases: before_or_equal
, before-or-equal
, boe
usage: before_or_equal:value
options:
value
- This option is required. It defines the value to compare to. The data type could bestring
,number
ordate
.
The field under validation must be a value before or equal to the given date.
Date Equals
aliases: date_equals
, date-equals
, aoe
usage: date_equals:value
options:
value
- This option is required. It defines the value to compare to. The data type could bestring
,number
ordate
.
The field under validation must be equal
to the given date
.
Positive
aliases: positive
Validates that a value is a positive
number. Zero is neither positive nor negative, so you must use Positive Or Zero
if you want to allow zero as value.
Positive Or Zero
aliases: positive
Validates that a value is a positive
number or equal to zero
.
Negative
aliases: negative
Validates that a value is a negative
number. Zero is neither positive nor negative, so you must use Negative Or Zero
if you want to allow zero as value.
Negative Or Zero
aliases: negative-or-zero
, noz
Validates that a value is a negative
number or equal to zero
.
Date
aliases: date
Validates that a value is a valid date
, meaning a string (or an object that can be cast into a string) that follows a valid YYYY-MM-DD
format.
Date Time
Date Format
aliases: date-time
, date_format
, date-format
usage: date_format:format
options:
format
- This option allows to validate a custom date format. Default: "YYYY-MM-DD HH:mm:ss
"
Validates that a value is a valid "datetime", meaning a string (or an object that can be cast into a string) that follows a specific format.
Year, month, and day tokens
Tokens are case-sensitive.
Input | Example | Description |
---|---|---|
YYYY |
2014 |
4 or 2 digit year |
YY |
14 |
2 digit year |
Y |
-25 |
Year with any number of digits and sign |
Q |
1..4 |
Quarter of year. Sets month to first month in quarter. |
M MM |
1..12 |
Month number |
MMM MMMM |
Jan..December |
Month name in locale that is specified |
D DD |
1..31 |
Day of month |
Do |
1st..31st |
Day of month with ordinal |
DDD DDDD |
1..365 |
Day of year |
X |
1410715640.579 |
Unix timestamp |
x |
1410715640579 |
Unix ms timestamp |
Week year, week, and weekday tokens
Tokens are case-sensitive.
Input | Example | Description |
---|---|---|
gggg |
2014 |
Locale 4 digit week year |
gg |
14 |
Locale 2 digit week year |
w ww |
1..53 |
Locale week of year |
e |
0..6 |
Locale day of week |
ddd dddd |
Mon...Sunday |
Day name in locale that is specified |
GGGG |
2014 |
ISO 4 digit week year |
GG |
14 |
ISO 2 digit week year |
W WW |
1..53 |
ISO week of year |
E |
1..7 |
ISO day of week |
Locale aware formats
Tokens are case-sensitive.
Input | Example | Description |
---|---|---|
L |
04/09/1986 |
Date (in local format) |
LL |
September 4 1986 |
Month name, day of month, year |
LLL |
September 4 1986 8:30 PM |
Month name, day of month, year, time |
LLLL |
Thursday, September 4 1986 8:30 PM |
Day of week, month name, day of month, year, time |
LT |
08:30 PM |
Time (without seconds) |
LTS |
08:30:00 PM |
Time (with seconds) |
Hour, minute, second, millisecond, and offset tokens
Tokens are case-sensitive.
Input | Example | Description |
---|---|---|
H HH |
0..23 |
Hours (24 hour time) |
h hh |
1..12 |
Hours (12 hour time used with a A .) |
k kk |
1..24 |
Hours (24 hour time from 1 to 24) |
a A |
am pm |
Post or ante meridiem (Note the one character a p are also considered valid) |
m mm |
0..59 |
Minutes |
s ss |
0..59 |
Seconds |
S SS SSS |
0..999 |
Fractional seconds |
Z ZZ |
+12:00 |
Offset from UTC as +-HH:mm , +-HHmm , or Z |
Time
aliases: time
Validates that a value is a valid time
, meaning a string (or an object that can be cast into a string) that follows a valid HH:mm:ss
format.
Timezone
aliases: timezone
, tz
Validates that a value is a valid timezone identifier (e.g. Europe/Paris
). List of tz database time zones.
Choice
aliases: choice
usage: choice:foo;bar;...,min,max,multiple
options:
choices
- A required option (unless callback is specified) - this is the array of options that should be considered in the valid set. The input value will be matched against this array.min
- If the multiple option is true, then you can use the min option to force at least XX number of values to be selected. For example, if min is 3, but the input array only contains 2 valid items, the validation will fail.max
- If the multiple option is true, then you can use the max option to force no more than XX number of values to be selected. For example, if max is 3, but the input array contains 4 valid items, the validation will fail.multiple
- If this option is true, the input value is expected to be an array instead of a single, scalar value. The constraint will check that each value of the input array can be found in the array of valid choices. If even one of the input values cannot be found, the validation will fail. Default: false.
This constraint is used to ensure that the given value is one of a given set of valid choices. It can also be used to validate that each item in an array of items is one of those valid choices.
Not In
aliases: not_in
, not-in
usage: not_in:foo;bar;...
options:
choices
- A required option - this is the array of options that should be considered in the valid set. The input value will be matched against this array.
The field under validation must not be included in the given list of values.
In
aliases: in
usage: in:foo;bar;...
options:
choices
- A required option - The field under validation must be included in the given list of values. The input value will be matched against this array.
The field under validation must be included in the given list of values.
Language
aliases: language
, lang
Validates that a value is a valid language Unicode language identifier (e.g. fr
or ar-dz
).
Locale
aliases: locale
Validates that a value is a valid locale. The "value
" for each locale is any of the ICU format locale IDs. For example, the two letter ISO 639-1 language code (e.g. fr
), or the language code followed by an underscore (_
) and the ISO 3166-1 alpha-2 country code (e.g. fr_FR for French/France). The given locale values are canonicalized before validating them to avoid issues with wrong uppercase/lowercase values and to remove unneeded elements (e.g. FR-fr.utf8
will be validated as fr_FR
).
Country
aliases: country
Validates that a value is a valid 3166-1 alpha-2 country code
.
File
aliases: file
Under development ...
Image
aliases: image
Under development ...
Bic
aliases: bic
usage: bic:iban
options:
iban
- An IBAN value to validate that the BIC is associated with it. Default: null.
This constraint is used to ensure that a value has the proper format of a Business Identifier Code (BIC). BIC
is an internationally agreed means to uniquely identify both financial and non-financial institutions. You may also check that the BIC
is associated with a given IBAN
.
Card Scheme
aliases: card-scheme
, cs
usage: card-scheme:schemes
options:
schemes
- This option is required and represents the name of the number scheme used to validate the credit card number, it can either be a string or an array. Valid values are:AMEX
,CHINA_UNIONPAY
,DINERS
,DISCOVER
,INSTAPAYMENT
,JCB
,LASER
,MAESTRO
,MASTERCARD
,MIR
,UATP
,VISA
This constraint ensures that a credit card number is valid for a given credit card company. It can be used to validate the number before trying to initiate a payment through a payment gateway.
Currency
aliases: currency
Validates that a value is a valid 3-letter ISO 4217 currency
name.
Luhn
aliases: luhn
This constraint is used to ensure that a credit card
number passes the Luhn algorithm. It is useful as a first step to validating a credit card: before communicating with a payment gateway.
Iban
aliases: iban
This constraint is used to ensure that a bank account number has the proper format of an International Bank Account Number (IBAN). IBAN
is an internationally agreed means of identifying bank accounts across national borders with a reduced risk of propagating transcription errors.
Isbn
aliases: isbn
This constraint validates that an International Standard Book Number (ISBN) is either a valid ISBN-10
or a valid ISBN-13
.
Issn
aliases: issn
usage: issn:caseSensitive,requireHyphen
options:
caseSensitive
- This is optional parameter. The validator will allowISSN
values to end with a lower case 'x
' by default. When switching this totrue
, the validator requires an upper case 'X
'. Default:false
.requireHyphen
- This is optional parameter. The validator will allow non hyphenatedISSN
values by default. When switching this totrue
, the validator requires a hyphenatedISSN
value. Default:false
.
Validates that a value is a valid International Standard Serial Number (ISSN).
Count
aliases: count
usage: count:min,max
options:
min
- This option is the "min
" count value. Validation will fail if the given collection elements count is less than this min value. This option is required when the max option is not defined.max
- This option is the "max
" count value. Validation will fail if the given collection elements count is greater than this max value. This option is required when the min option is not defined.
Validates that a given collection's (i.e. an array or an object that implements Countable) element count
is between
some minimum
and maximum
value.
Any
aliases: any
, one-of
usage: any:string;alnum;...
options:
rules
- This option is required. This is the list of validation rules.
Validates that a value is valid at least for one of the rule.
License (MIT)
Copyright (c) 2020 Slave of God <iamtheslaveofgod@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.