sog-validator

A library of validators

Usage no npm install needed!

<script type="module">
  import sogValidator from 'https://cdn.skypack.dev/sog-validator';
</script>

README

sog-validator

NPM version Downloads Build Status DeepScan grade jsDelivr

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';

⬆ navigation

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>

⬆ navigation

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, or true.
  • 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 and maximum 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 and maximum.
  • Between - The field under validation must have a size between the given min and max.
  • Digits Between - The field under validation must be numeric and must have a length between the given min and max.
  • 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 exact length 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 given date.

Number Constraints

  • Positive - Validates that a value is a positive number.
  • Positive Or Zero - Validates that a value is a positive number or equal to zero.
  • Negativeaaa - Validates that a value is a negative number.
  • Negative Or Zero - Validates that a value is a negative number or equal to zero.

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 valid YYYY-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 valid HH: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 or ar-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

  • File - Under development ...
  • Image - Under development ...

Financial and other Number Constraints

Other Constraints

  • Count - 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 - Validates that a value is valid at least for one of the rule.

⬆ navigation

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.

⬆ navigation


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.

⬆ navigation


Blank

aliases: blank, empty

Validates that a value is blank - meaning equal to an empty string or null.

⬆ navigation


Not Null

aliases: not-null, required, present

Validates that a value is not strictly equal to null.

⬆ navigation


Is Null

aliases: is-null, nullable

Validates that a value is exactly equal to null.

⬆ navigation


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".

⬆ navigation


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".

⬆ navigation


Alpha Dash

aliases: alpha_dash, alpha-dash

The field under validation may have alpha-numeric characters, as well as dashes and underscores.

⬆ navigation


Array

aliases: array, arr

The field under validation must be an array.

⬆ navigation


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".

⬆ navigation


Callable

aliases: callable

Verify that the contents of a variable can be called as a function.

⬆ navigation


Float

aliases: float

The field under validation must be a float.

⬆ navigation


Double

aliases: double

The field under validation must be a double.

⬆ navigation


Integer

aliases: int, integer

The field under validation must be an integer.

⬆ navigation


Iterable

aliases: iterable

Verify that the contents of a variable is an iterable value.

⬆ navigation


Null

aliases: null

The field under validation must be a NULL.

⬆ navigation


Numeric

aliases: numeric, num

The field under validation must be a number or a numeric string.

⬆ navigation


Object

aliases: object

The field under validation must be an object.

⬆ navigation


Real

aliases: real

Finds whether the type of a variable is real.

⬆ navigation


Scalar

aliases: scalar

Finds whether a variable is a scalar. Scalar variables are those containing an integer, float, string or boolean.

⬆ navigation


String

aliases: string, str

The field under validation must be a string.

⬆ navigation


Alnum

aliases: alnum, alpha-num, alpha_num

Check for alphanumeric character(s).

⬆ navigation


Alpha

aliases: alpha

Check for alphabetic character(s).

⬆ navigation


Cntrl

aliases: cntrl

Check for control character(s).

⬆ navigation


Digit

aliases: digit

Check for numeric character(s).

⬆ navigation


Graph

aliases: graph

Check for any printable character(s) except space.

⬆ navigation


Lower

aliases: lower

Check for lowercase character(s).

⬆ navigation


Print

aliases: print

Check for printable character(s).

⬆ navigation


Punct

aliases: punct

Check for any printable character which is not whitespace or an alphanumeric character.

⬆ navigation


Space

aliases: space

Check for whitespace character(s).

⬆ navigation


Upper

aliases: upper

Check for uppercase character(s).

⬆ navigation


Xdigit

aliases: xdigit

Check for character(s) representing a hexadecimal digit.

⬆ navigation


Email

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 the HTML5 email input element.

Validates that a value is a valid email address.

⬆ navigation


Length

aliases: length, len

usage: length:min,max

Validates that a given string length is between some minimum and maximum value.

⬆ navigation


Url

aliases: url

Validates that a value is a valid URL string.

⬆ navigation


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 - If true (or not set), this validator will pass if the given string matches the given pattern regular expression. However, when this option is set to false, 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.

⬆ navigation


Ip

aliases: ip

Validates that a value is a valid IP address.

⬆ navigation


IPv4

aliases: ipv4

The field under validation must be an IPv4 address.

⬆ navigation


IPv6

aliases: ipv6

The field under validation must be an IPv6 address.

⬆ navigation


Json

aliases: json

Validates that a value has valid JSON syntax.

⬆ navigation


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).

⬆ navigation


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.

⬆ navigation


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.

⬆ navigation


Contains

aliases: contains

usage: contains:value

options:

  • value - The option is required. The substring.

The field under validation must contains the given substring.

⬆ navigation


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 a string, number or object.

Validates that a value is equal to another value, defined in the options. This constraint compares using ==, so 3 and "3" are considered equal.

⬆ navigation


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 a string, number or object.

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.

⬆ navigation


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 a string, number or object.

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.

⬆ navigation


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 a string, number or object.

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.

⬆ navigation


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 a string, number or date object.

Validates that a value is less than another value, defined in the options.

⬆ navigation


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 a string, number or date object.

Validates that a value is less than or equal to another value, defined in the options.

⬆ navigation


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 a string, number or date object.

Validates that a value is greater than another value, defined in the options.

⬆ navigation


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 a string, number or date object.

Validates that a value is greater than or equal to another value, defined in the options.

⬆ navigation


Range

aliases: range

usage: range:min,max

Validates that a given number or Date object is between some minimum and maximum.

⬆ navigation


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.

⬆ navigation


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.

⬆ navigation


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 a number or date object.

Validates that a value is divisible by another value, defined in the options.

⬆ navigation


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.

⬆ navigation


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.

⬆ navigation


Distinct

aliases: distinct

When working with arrays, the field under validation must not have any duplicate values.

⬆ navigation


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.

⬆ navigation


After (Date)

aliases: after

usage: after:value

options:

  • value - This option is required. It defines the value to compare to. The data type could be string, number or date.

The field under validation must be a value after a given date.

⬆ navigation


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 be string, number or date.

The field under validation must be a value after or equal to the given date.

⬆ navigation


Before (Date)

aliases: before

usage: before:value

options:

  • value - This option is required. It defines the value to compare to. The data type could be string, number or date.

The field under validation must be a value before a given date.

⬆ navigation


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 be string, number or date.

The field under validation must be a value before or equal to the given date.

⬆ navigation


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 be string, number or date.

The field under validation must be equal to the given date.

⬆ navigation


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.

⬆ navigation


Positive Or Zero

aliases: positive

Validates that a value is a positive number or equal to zero.

⬆ navigation


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.

⬆ navigation


Negative Or Zero

aliases: negative-or-zero, noz

Validates that a value is a negative number or equal to zero.

⬆ navigation


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.

⬆ navigation


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

⬆ navigation


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.

⬆ navigation


Timezone

aliases: timezone, tz

Validates that a value is a valid timezone identifier (e.g. Europe/Paris). List of tz database time zones.

⬆ navigation


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.

⬆ navigation


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.

⬆ navigation


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.

⬆ navigation


Language

aliases: language, lang

Validates that a value is a valid language Unicode language identifier (e.g. fr or ar-dz).

⬆ navigation


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).

⬆ navigation


Country

aliases: country

Validates that a value is a valid 3166-1 alpha-2 country code.

⬆ navigation


File

aliases: file

Under development ...

⬆ navigation


Image

aliases: image

Under development ...

⬆ navigation


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.

⬆ navigation


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.

⬆ navigation


Currency

aliases: currency

Validates that a value is a valid 3-letter ISO 4217 currency name.

⬆ navigation


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.

⬆ navigation


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.

⬆ navigation


Isbn

aliases: isbn

This constraint validates that an International Standard Book Number (ISBN) is either a valid ISBN-10 or a valid ISBN-13.

⬆ navigation


Issn

aliases: issn

usage: issn:caseSensitive,requireHyphen

options:

  • caseSensitive - This is optional parameter. The validator will allow ISSN values to end with a lower case 'x' by default. When switching this to true, the validator requires an upper case 'X'. Default: false.

  • requireHyphen - This is optional parameter. The validator will allow non hyphenated ISSN values by default. When switching this to true, the validator requires a hyphenated ISSN value. Default: false.

Validates that a value is a valid International Standard Serial Number (ISSN).

⬆ navigation


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.

⬆ navigation


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.

⬆ navigation


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.