class Validation extends Expression (View source)

Validator aware validation expression builder.

{@inheritDoc}

Example:

$validation = (new Validation())->required()->string()->between(2, 255)->or()->null();

$validation = Validation::required()->string()->between(2, 255)->or()->null()->build();

Rules:

Constants

BEHAVIORS

Expression behaviors.

OPERATORS

Expression operators.

Properties

protected string $buffer

Expression string buffer.

from  Expression
protected array $tokens

Expression string buffer tokens.

from  Expression
protected Validator|null $validator

Associated Validator instance.

Methods

mixed
__call(string $name, array $arguments)

Provides rules and aliases as class methods.

static mixed
__callStatic(string $name, array $arguments)

Provides rules and aliases as static class methods.

__construct(Validator|null $validator = null)

Validation constructor.

string
__toString()

Returns the current expression string.

static static
accepted() $dds `accepted` rule. Asserts that the input is accepted (equals: "on", "aye" $, 1 $r "1", true $r "true")

note that strings are treated in a case-insensitive manner.

add(Expression $validation)

Adds a validation string or object as a group to the current validation expression.

static static
allowed() $dds `allowed` rule. Asserts that the input is allowed (can be empty or have any value, null $nd empty string are considered valid values)

.

static static
alnum()

Adds alnum rule. Asserts that the input consists of alphanumeric characters only.

static static
alpha()

Adds alpha rule. Asserts that the input consists of alphabetic characters only.

static static
amount() $dds `amount` rule. Asserts that the input contains only numbers, an $ptional decimal point (comma or dot), and $n optional minus (used for amounts of money for example)

.

static static
amountDollar()

Adds amount.dollar rule. Asserts that the input is a validly formatted amount of USD, where decimal point and thousands separator are optional.

static static
amountEuro()

Adds amount.euro rule. Asserts that the input is a validly formatted amount of EUR, where decimal point and thousands separator are optional.

and()

Adds AND operator (ampersand: &) (default). Ands the next rule/group.

static static
arr()

Adds arr rule. An alias for the array rule.

static static
array()

Adds array rule. Asserts that the input is an array.

static static
arrayHasDistinct(string|int $key)

Adds array.hasDistinct rule. Asserts that the input is a multidimensional array that contains distinct values of the given key.

static static
arrayHasKey(string|int $key)

Adds array.hasKey rule. Asserts that the input array has the given key.

static static
arrayHasValue(mixed $value)

Adds array.hasValue rule. Asserts that the input array contains the given value. Works with scalar types.

static static
arrayIsAssociative()

Adds array.isAssociative rule. Asserts that the input is an associative array.

static static
arrayIsSequential()

Adds array.isSequential rule. Asserts that the input is a sequential array.

static static
arrayIsUnique()

Adds array.isUnique rule. Asserts that the input array contains unique values. Works only with one-dimensional arrays.

static static
arraySubset(array $subset)

Adds array.subset rule. Asserts that the input is an array that contains the given subset. Note that this check applies only to the first dimension of the array.

static static
ascii() $dds `ascii` rule. Asserts that the input is a string containing only ASCII characters (ASCII compliant string)

.

static static
assert(mixed $actual, mixed $expected = true, string $operator = '==')

Adds assert rule. An alias for the if rule.

static static
assertEquals(mixed $actual, mixed $expected)

Adds assert.equals rule. An alias for the if.eq rule.

static static
assertGreaterThan(mixed $actual, mixed $expected)

Adds assert.greaterThan rule. An alias for the if.gt rule.

static static
assertGreaterThanOrEquals(mixed $actual, mixed $expected)

Adds assert.greaterThanOrEquals rule. An alias for the if.gte rule.

static static
assertLessThan(mixed $actual, mixed $expected)

Adds assert.lessThan rule. An alias for the if.lt rule.

static static
assertLessThanOrEquals(mixed $actual, mixed $expected)

Adds assert.lessThanOrEquals rule. An alias for the if.lte rule.

static static
assertNotEquals(mixed $actual, mixed $expected)

Adds assert.notEquals rule. An alias for the if.neq rule.

static static
base64()

Adds base64 rule. Asserts that the input is a valid Base64 encoded string.

static static
between(int|float $min, int|float $max) Adds `between` rule. Asserts that the input count is between the given values. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count)

.

static static
bic() $dds `bic` rule. Asserts that the input is a valid BIC (Bank Identifier Code)

.

static static
bit() $dds `bit` rule. Asserts that the input is bit (equals: 1 or "1", true; $or "0", false $)

.

static static
bitIsOff() $dds `bit.isOff` rule. Asserts that the input is a turned off bit (equals: false, $r "0")

.

static static
bitIsOn() $dds `bit.isOn` rule. Asserts that the input is a turned on bit (equals: true, 1 $r "1")

.

static static
blank()

Adds blank rule. An alias for the empty rule.

static static
bool()

Adds bool rule. An alias for the boolean rule.

static static
boolean()

Adds boolean rule. Asserts that the input is a boolean.

static static
booleanLike() $dds `booleanLike` rule. Asserts that the input is value that can be parsed as a boolean (TRUE: true, null $, "yes"; $ALSE: false)

.

string
build()

Returns the current expression string.

static static
cakeday()

Adds cakeday rule. An alias for the datetime.birthday rule.

static static
calenderDay() $dds `calender.day` rule. Asserts that the input looks like a calendar dayin shot or long format ("Mon" or "Monday")

.

static static
calenderMonth() $dds `calender.month` rule. Asserts that the input looks like a calendar month in shot or long format ("Jan" or "January")

.

static static
callable()

Adds callable rule. Asserts that the input is a callable.

callback(callable $callback, string|null $id = null)

Writes a rule to the current validation expression that executes the passed callback.

static static
choice(string|int|float|bool|null $values)

Adds choice rule. An alias for the in rule.

close()

Adds CLOSE operator (closing parenthesis: )). Ends the current group.

static static
cntrl()

Adds cntrl rule. Asserts that the input consists of control characters only.

static static
color() $dds `color` rule. Asserts that the input is a valid CSS color (Color Word, HSLA $)

.

static static
colorHex()

Adds color.hex rule. Asserts that the input is a valid CSS HEX color.

static static
colorHexAlpha() $dds `color.hexAlpha` rule. Asserts that the input is a valid CSS HEX-Alpha (4 or 8 Chars)

color.

static static
colorHexLong()

Adds color.hexLong rule. Asserts that the input is a valid CSS 6-Char-HEX color.

static static
colorHexShort()

Adds color.hexShort rule. Asserts that the input is a valid CSS 3-Char-HEX color.

static static
colorHsl()

Adds color.hsl rule. Asserts that the input is a valid CSS HSL color.

static static
colorHslNew()

Adds color.hsl.new rule. Asserts that the input is a valid CSS4 HSL color.

static static
colorHsla()

Adds color.hsla rule. Asserts that the input is a valid CSS HSLA color.

static static
colorKeyword()

Adds color.keyword rule. Asserts that the input is a valid CSS YYY color.

static static
colorRgb()

Adds color.rgb rule. Asserts that the input is a valid CSS RGB color.

static static
colorRgbNew()

Adds color.rgb.new rule. Asserts that the input is a valid CSS4 RGB color.

static static
colorRgba()

Adds color.rgba rule. Asserts that the input is a valid CSS RGBA color.

static string
comment(string $text)

Returns a the passed string as a valid comment.

concat(string $string)

Writes the passed string to the current expression string buffer.

static static
count(int $count) Adds `count` rule. Asserts that the input count is equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count)

.

static static
countable()

Adds countable rule. Asserts that the input is a countable.

static static
country(bool $long = false) Adds `country` rule. Asserts that the input is a valid country code (default: "ISO 3166-1 alpha-2"; long: "ISO 3166-1 alpha-3")

.

string
createRuleStatement(string $name, array $arguments)

Returns a valid rule statement from the passed name and arguments.

static static
creditcard()

Adds creditcard rule. Asserts that the input is a valid credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardAmericanExpress()

Adds creditcard.americanExpress rule. Asserts that the input is a valid American Express credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardChinaUnionPay()

Adds creditcard.chinaUnionPay rule. Asserts that the input is a valid China UnionPay credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardDinersClub()

Adds creditcard.dinersClub rule. Asserts that the input is a valid Diners Club credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardDiscover()

Adds creditcard.discover rule. Asserts that the input is a valid Discover credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardInstaPayment()

Adds creditcard.instaPayment rule. Asserts that the input is a valid InstaPayment credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardJcb()

Adds creditcard.jcb rule. Asserts that the input is a valid JCB credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardLaser()

Adds creditcard.laser rule. Asserts that the input is a valid Laser credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardMaestro()

Adds creditcard.maestro rule. Asserts that the input is a valid Maestro credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardMastercard()

Adds creditcard.mastercard rule. Asserts that the input is a valid Mastercard credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardMir()

Adds creditcard.mir rule. Asserts that the input is a valid MIR Payment System card number, balanced spaces and/or dashes are allowed.

static static
creditcardUatp()

Adds creditcard.uatp rule. Asserts that the input is a valid UATP credit card number, balanced spaces and/or dashes are allowed.

static static
creditcardVisa()

Adds creditcard.visa rule. Asserts that the input is a valid Visa credit card number, balanced spaces and/or dashes are allowed.

static static
currency(bool $numeric = false) Adds `currency` rule. Asserts that the input is a valid currency code (default: "ISO 4217 alpha"; numeric: "ISO 4217 numeric")

.

static static
currencyName() $dds `currency.name` rule. Asserts that the input is a valid currency name (as in ISO 4217)

.

static static
cvv() $dds `cvv` rule. Asserts that the input is a valid CVV (Card Security Code)

.

static static
date()

Adds date rule. An alias for the datetime rule.

static static
dateAfter(string $datetime)

Adds date.after rule. An alias for the datetime.gt rule.

static static
dateAfterOrEquals(string $datetime)

Adds date.afterOrEquals rule. An alias for the datetime.gte rule.

static static
dateBefore(string $datetime)

Adds date.before rule. An alias for the datetime.lt rule.

static static
dateBeforeOrEquals(string $datetime)

Adds date.beforeOrEquals rule. An alias for the datetime.lte rule.

static static
dateEquals(string $datetime)

Adds date.equals rule. An alias for the datetime.eq rule.

static static
dateFormat(string $format)

Adds date.format rule. An alias for the datetime.format rule.

static static
datestamp()

Adds datestamp rule. Asserts that the input looks like a human datestamp, DMY or MDY format, separated with dot, dash, or slash.

static static
datestampDmy()

Adds datestamp.dmy rule. Asserts that the input looks like a human DMY-formatted datestamp, separated with dot, dash, or slash.

static static
datestampMdy()

Adds datestamp.mdy rule. Asserts that the input looks like a human MDY-formatted datestamp, separated with dot, dash, or slash.

static static
datestampYmd()

Adds datestamp.ymd rule. Asserts that the input looks like a human YMD-formatted datestamp, separated with dot, dash, or slash.

static static
datetime()

Adds datetime rule. Asserts that the input is a valid datetime string/object.

static static
datetimeBirthday()

Adds datetime.birthday rule. Asserts that the input is a datetime string/object that has birthday today. Input should preferably be in "YYYY-MM-DD" format.

static static
datetimeEq(string $datetime)

Adds datetime.eq rule. Asserts that the input is a datetime string/object equal to the given datetime string.

static static
datetimeFormat(string $format)

Adds datetime.format rule. Asserts that the input is a valid datetime with the given format.

static static
datetimeFormatGlobal()

Adds datetime.format.global rule. Asserts that the input looks like a valid global datetime string as defined in the HTML5 specification.

static static
datetimeFormatLocal()

Adds datetime.format.local rule. Asserts that the input looks like a valid local datetime string as defined in the HTML5 specification.

static static
datetimeGt(string $datetime) Adds `datetime.gt` rule. Asserts that the input is a datetime string/object greater than (after)

the given datetime string.

static static
datetimeGte(string $datetime) Adds `datetime.gte` rule. Asserts that the input is a datetime string/object greater than (after)

or equal to the given datetime string.

static static
datetimeLt(string $datetime) Adds `datetime.lt` rule. Asserts that the input is a datetime string/object less than (before)

the given datetime string.

static static
datetimeLte(string $datetime) Adds `datetime.lte` rule. Asserts that the input is a datetime string/object less than (before)

or equal to the given datetime string.

static static
declined() $dds `declined` rule. Asserts that the input is declined (equals: "off", "nay" $, $r "0", false $r "false")

note that strings are treated in a case-insensitive manner.

static static
digit() $dds `digit` rule. Asserts that the input consists of a digits only (numeric characters)

.

static static
domain()

Adds domain rule. Asserts that the input is a domain.

static static
domainIsActive()

Adds domain.isActive rule. Asserts that the input is an active domain. Works with domains and emails.

static static
double()

Adds double rule. An alias for the float rule.

static static
email()

Adds email rule. Asserts that the input is an email address.

static static
emailWithUnicode() $dds `email.withUnicode` rule. Asserts that the input is an email address (unicode allowed)

.

static static
emoji()

Adds emoji rule. Asserts that the input contains an emoji.

static static
empty() $dds `empty` rule. Asserts that the input is empty using empty() language construct (is blank, i.e. $mpty string, empty $rray, or $)

.

static static
equals(string|int|float|bool|null $value)

Adds equals rule. Asserts that the input is equal to the given value. Works with scalar types and null. Comparison operator is "==".

static static
esn() $dds `esn` rule. Asserts that the input is a valid ESN (Electronic Serial Number)

.

static static
file() $dds `file` rule. Asserts that the input is a file (can be a file, a $ink, or $directory)

.

static static
fileBasename(string $basename)

Adds file.basename rule. Asserts that the input is a file and its basename is equal to the given basename.

static static
fileDirname(string $dirname)

Adds file.dirname rule. Asserts that the input is a file and its dirname is equal to the given dirname.

static static
fileExtension(string $extension)

Adds file.extension rule. Asserts that the input is a file and its extension is equal to the given extension.

static static
fileFilename(string $filename)

Adds file.filename rule. Asserts that the input is a file and its filename is equal to the given filename.

static static
fileIsDirectory()

Adds file.isDirectory rule. Asserts that the input is a directory.

static static
fileIsExecutable()

Adds file.isExecutable rule. Asserts that the input is a file and is executable.

static static
fileIsFile()

Adds file.isFile rule. Asserts that the input is a file.

static static
fileIsLink()

Adds file.isLink rule. Asserts that the input is a link.

static static
fileIsReadable()

Adds file.isReadable rule. Asserts that the input is a file and is readable.

static static
fileIsUploaded()

Adds file.isUploaded rule. Asserts that the input is a file that is uploaded via HTTP POST.

static static
fileIsWritable()

Adds file.isWritable rule. Asserts that the input is a file and is writable.

static static
fileMime(string|array $mine)

Adds file.mime rule. Asserts that the input is a file and its MIME type is one of the given MIME types.

static static
fileSize(int $sizeInBytes)

Adds file.size rule. Asserts that the input is a file and the size is equal to the given size in bytes.

static static
fileSizeGte(int $sizeInBytes)

Adds file.size.gte rule. Asserts that the input is a file and the size is greater than or equal to the given size in bytes.

static static
fileSizeLte(int $sizeInBytes)

Adds file.size.lte rule. Asserts that the input is a file and the size is less than or equal to the given size in bytes.

static static
filled()

Adds filled rule. An alias for the required rule.

static static
float()

Adds float rule. Asserts that the input is a float.

static static
floatLike(float $min = PHP_FLOAT_MIN, float $max = PHP_FLOAT_MAX)

Adds floatLike rule. Asserts that the input is a value that can be parsed as a float within the specifed range.

static static
floatLikeAllowThousands(float $min = PHP_FLOAT_MIN, float $max = PHP_FLOAT_MAX)

Adds floatLike.allowThousands rule. Asserts that the input is a value that can be parsed as a float within the specifed range.

static static
forbidden() $dds `forbidden` rule. Asserts that the input is forbidden (is null or not present)

.

static static
geolocation() $dds `geolocation` rule. Asserts that the input is a valid geolocation (latitude and longitude coordinates combination)

.

string
getBehaviorChars()

No description

string
getHashedName(string $name)

Returns a consistent hash for the rule name.

array
getHashedNames()

Returns an associative array of rule names and their corresponding hashes.

array
getOperatorChars()

No description

static static
graph() $dds `graph` rule. Asserts that the input consists of graphic characters only (characters that create a visible output)

.

group(callable $callback)

Groups a set of rules inside a pair of parentheses ().

static static
iban(?string $country = null) Adds `iban` rule. Asserts that the input is a valid IBAN (International Bank Account Number)

. The "ISO 3166-1 alpha-2" country code can be specifed to narrow the pattern.

static static
if(mixed $actual, mixed $expected = true, string $operator = '==')

Adds if rule. Checks the condition between the first argument and the second argument, the condition operator can also be specified as the third argument.

static static
ifEq(mixed $actual, mixed $expected)

Adds if.eq rule. Checks the condition between the first argument and the second argument, the condition operator is "==".

static static
ifGt(mixed $actual, mixed $expected)

Adds if.gt rule. Checks the condition between the first argument and the second argument, the condition operator is ">".

static static
ifGte(mixed $actual, mixed $expected)

Adds if.gte rule. Checks the condition between the first argument and the second argument, the condition operator is ">=".

static static
ifId(mixed $actual, mixed $expected)

Adds if.id rule. Checks the condition between the first argument and the second argument, the condition operator is "===".

static static
ifLt(mixed $actual, mixed $expected)

Adds if.lt rule. Checks the condition between the first argument and the second argument, the condition operator is "<".

static static
ifLte(mixed $actual, mixed $expected)

Adds if.lte rule. Checks the condition between the first argument and the second argument, the condition operator is "<=".

static static
ifNeq(mixed $actual, mixed $expected)

Adds if.neq rule. Checks the condition between the first argument and the second argument, the condition operator is "!=".

static static
ifNid(mixed $actual, mixed $expected)

Adds if.nid rule. Checks the condition between the first argument and the second argument, the condition operator is "!==".

static static
image() $dds `image` rule. Asserts that the input is an image file (jpg, svg $, or $ebp)

.

static static
imageDimensions(int $width, int $height, string $operator = '==')

Adds image.dimensions rule. Asserts that the input is an image and its dimensions are less than, equal to, or greater than the given width and height in pixels.

static static
imageHeight(int $height)

Adds image.height rule. Asserts that the input is an image and its height is equal to the given height in pixels.

static static
imageHeightGte(int $height)

Adds image.height.gte rule. Asserts that the input is an image and its height is greater than or equal to the given height in pixels.

static static
imageHeightLte(int $height)

Adds image.height.lte rule. Asserts that the input is an image and its height is less than or equal to the given height in pixels.

static static
imageRatio(string $ratio) Adds `image.ratio` rule. Asserts that the input is an image and its aspect ratio is equal to the given ratio (ratio must be specified like "16:9")

.

static static
imageWidth(int $width)

Adds image.width rule. Asserts that the input is an image and its width is equal to the given width in pixels.

static static
imageWidthGte(int $width)

Adds image.width.gte rule. Asserts that the input is an image and its width is greater than or equal to the given width in pixels.

static static
imageWidthLte(int $width)

Adds image.width.lte rule. Asserts that the input is an image and its width is less than or equal to the given width in pixels.

static static
imei() $dds `imei` rule. Asserts that the input is a valid IMEI (International Mobile Station Equipment Identity Number)

.

static static
imeiSv() $dds `imei.sv` rule. Asserts that the input is a valid IMEI-SV (International Mobile Station Equipment Identity and Software Version Number)

.

static static
in(string|int|float|bool|null $values)

Adds in rule. Asserts that the input is in the given values. Works with scalar types and null.

static static
int()

Adds int rule. An alias for the integer rule.

static static
integer()

Adds integer rule. Asserts that the input is an integer.

static static
integerLike(int $min = PHP_INT_MIN, int $max = PHP_INT_MAX)

Adds integerLike rule. Asserts that the input is a value that can be parsed as an integer within the specifed range.

static static
integerLikeAllowHex(int $min = PHP_INT_MIN, int $max = PHP_INT_MAX)

Adds integerLike.allowHex rule. Asserts that the input is a value that can be parsed as an integer within the specifed range and can be in hexadecimal notation.

static static
integerLikeAllowOctal(int $min = PHP_INT_MIN, int $max = PHP_INT_MAX)

Adds integerLike.allowOctal rule. Asserts that the input is a value that can be parsed as an integer within the specifed range and can be in octal notation.

static static
ip()

Adds ip rule. Asserts that the input is an IP address.

static static
ipNotPrivate()

Adds ip.notPrivate rule. Asserts that the input is an IP address not within private IPs range.

static static
ipNotReserved()

Adds ip.notReserved rule. Asserts that the input is an IP address not within reserved IPs range.

static static
ipV4()

Adds ip.v4 rule. Asserts that the input is an IPv4 address.

static static
ipV6()

Adds ip.v6 rule. Asserts that the input is an IPv6 address.

static static
is(mixed $value)

Adds is rule. An alias for the equals rule.

static static
isbn(string|int|null $type = null) Adds `isbn` rule. Asserts that the input is a valid ISBN (International Standard Book Number). The type (10/13)

can be specifed to narrow the pattern.

static static
isin() $dds `isin` rule. Asserts that the input is a valid ISIN (International Securities Identification Number)

.

static static
issn() $dds `issn` rule. Asserts that the input is a valid ISSN (International Standard Serial Number)

.

static static
iterable()

Adds iterable rule. Asserts that the input is an iterable.

static static
json()

Adds json rule. Asserts that the input is a valid JSON.

static static
language(bool $long = false) Adds `language` rule. Asserts that the input is a valid language code (default: "ISO 639-1"; long: "ISO 639-2/T")

.

static static
length(int $count)

Adds length rule. An alias for the count rule.

static static
locale(bool $strict = false) Adds `locale` rule. Asserts that the input is a valid locale identifier (default: [ISO 639-1] or [ISO 639-1]_[ISO 3166-1 alpha-2], case-insensitive $, input $s canonicalized before checking (dashes to underscores, no $ots or charset)

; strict: [ISO 639-1] or [ISO 639-1]_[ISO 3166-1 alpha-2], case-sensitive without canonicalization.

static static
long()

Adds long rule. An alias for the integer rule.

static static
lower()

Adds lower rule. Asserts that the input consists of lowercase characters only.

static static
luhn()

Adds luhn rule. Asserts that the input passes the Luhn Algorithm check. This rule is mostly used in conjunction with other rules like credit card numbers and identifiers to further check the validity of the subject.

static static
mac()

Adds mac rule. Asserts that the input is a MAC address.

macro(string $macro)

Writes a macro to the current expression string.

static static
matches(string $pattern)

Adds matches rule. Asserts that the input matches the given pattern. Works with strings only.

static static
max(int|float $count) Adds `max` rule. Asserts that the input count is less than or equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count)

.

static static
meid() $dds `meid` rule. Asserts that the input is a valid MEID (Mobile Equipment Identifier)

.

static static
meta() $dds `meta` rule. Asserts that the input is a string containing only meta characters (special characters) (i.e. "@, ..." $)

.

static static
min(int|float $count) Adds `min` rule. Asserts that the input count is greater than or equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count)

.

static static
minmax(int|float $min, int|float $max)

Adds minmax rule. An alias for the between rule.

static Validation
new()

Creates a new Validation instance that is bound to the default Validator.

static static
nino() $dds `nino` rule. Asserts that the input is a valid NINO (UK National Insurance Number)

.

normal()

Makes the expression normal (executes all checks). The is the default behavior.

not()

Adds NOT operator (tilde: ~). Negates the next rule/group.

static static
null()

Adds null rule. Asserts that the input is null.

static static
numberIsEven()

Adds number.isEven rule. Asserts that the input is an even number.

static static
numberIsFinite()

Adds number.isFinite rule. Asserts that the input is a finite number.

static static
numberIsInfinite()

Adds number.isInfinite rule. Asserts that the input is an infinite number.

static static
numberIsMultipleOf(float $number)

Adds number.isMultipleOf rule. Asserts that the input is a multiple of the given number.

static static
numberIsNan()

Adds number.isNan rule. Asserts that the input is a not a number.

static static
numberIsNegative()

Adds number.isNegative rule. Asserts that the input is a negative number.

static static
numberIsOdd()

Adds number.isOdd rule. Asserts that the input is an odd number.

static static
numberIsPositive()

Adds number.isPositive rule. Asserts that the input is a positive number.

static static
numeric()

Adds numeric rule. Asserts that the input is numeric.

static static
obj()

Adds obj rule. An alias for the object rule.

static static
object()

Adds object rule. Asserts that the input is an object.

static static
objectHasMethod(string $method)

Adds object.hasMethod rule. Asserts that the input has the given method.

static static
objectHasProperty(string $property)

Adds object.hasProperty rule. Asserts that the input has the given property.

static static
objectIsInstanceOf(string $classFQN)

Adds object.isInstanceOf rule. Asserts that the input is an instance of the given class.

static static
objectIsStringable() $dds `object.isStringable` rule. Asserts that the input implements __toString()

method.

static static
objectIsSubclassOf(string $classFQN)

Adds object.isSubclassOf rule. Asserts that the input is a subclass of the given class.

open()

Adds OPEN operator (opening parenthesis: (). Starts a new group.

optimistic()

Makes the expression optimistic (stop checking after first success).

static static
optional()

Adds optional rule. An alias for the allowed rule.

or()

Adds OR operator (pipe: |). Ors the next rule/group.

static static
password() $dds `password` rule. Asserts that the input is a valid password (minimum 8 characters, consists $f at least one small letter and one capital letter, at $east one number, at $east one special character, and $ptionally a space)

.

static static
pattern(string $pattern)

Adds pattern rule. An alias for the matches rule.

pessimistic()

Makes the expression pessimistic (stop checking after first failure).

static static
phone() $dds `phone` rule. Asserts that the input is a valid phone number (supports: North America, Europe $nd most Asian and Middle East countries)

.

static static
phpKeyword()

Adds php.keyword rule. Asserts that the input is a PHP language Keyword.

static static
phpReserved()

Adds php.reserved rule. Asserts that the input is a PHP language reserved word.

static static
phpReservedExtra()

Adds php.reserved.extra rule. Asserts that the input is a PHP language reserved word including soft reserved words.

static static
present()

Adds present rule. An alias for the required rule.

static static
print()

Adds print rule. Asserts that the input consists of printable characters only.

static static
punct()

Adds punct rule. Asserts that the input consists of punctuation characters only.

static static
range(int|float $min, int|float $max)

Adds range rule. An alias for the between rule.

static static
real()

Adds real rule. An alias for the float rule.

static static
regex()

Adds regex rule. Asserts that the input is a valid regular expression.

Aliases:

static static
regexp(string $pattern)

Adds regexp rule. Asserts that the input matches a Perl-compatible regular expression.

static static
required() $dds `required` rule. Asserts that the input is required (is not blank, i.e. $ot a empty string or null)

.

static static
resource()

Adds resource rule. Asserts that the input is a resource.

static static
roman()

Adds roman rule. Asserts that the input is a valid roman number.

rule(string $rule)

Writes a rule to the current expression string.

static static
same(mixed $value)

Adds same rule. An alias for the equals rule.

static static
scalar()

Adds scalar rule. Asserts that the input is a scalar.

static static
serialized()

Adds serialized rule. Asserts that the input is a valid PHP serialized data.

static static
sin() $dds `sin` rule. Asserts that the input is a valid SIN (CA Social Insurance Number)

.

static static
size(int $size)

Adds size rule. An alias for the count rule.

static static
slug()

Adds slug rule. Asserts that the input is a valid slug.

static static
space()

Adds space rule. Asserts that the input consists of whitespace characters only.

static static
spaceless()

Adds spaceless rule. Asserts that the input is a string containing no whitespace characters.

static static
ssn() $dds `ssn` rule. Asserts that the input is a valid SSN (Social Security Number)

.

static static
str()

Adds str rule. An alias for the string rule.

static static
stream()

Adds stream rule. An alias for the resource rule.

static static
string()

Adds string rule. Asserts that the input is a string.

static static
stringCharset(string|array $charset) Adds `string.charset` rule. Asserts that the input is encoded in one of the given charsets (aliases included)

. The check is done in a case-sensitive manner.

static static
stringContains(string $substring, bool $strict = false) Adds `string.contains` rule. Asserts that the input contains the given substring. A second boolean argument can be specified to enable strict mode (case-sensitive)

.

static static
stringEndsWith(string $substring, bool $strict = false) Adds `string.endsWith` rule. Asserts that the input ends with the given substring. A second boolean argument can be specified to enable strict mode (case-sensitive)

.

static static
stringLength(int $length)

Adds string.length rule. Asserts that the input is a string that is exactly the given length.

static static
stringStartsWith(string $substring, bool $strict = false) Adds `string.startsWith` rule. Asserts that the input starts with the given substring. A second boolean argument can be specified to enable strict mode (case-sensitive)

.

static static
stringWordsCount(int $count)

Adds string.wordsCount rule. Asserts that the input is a string containing exactly the given count of words.

static static
text()

Adds text rule. Asserts that the input is a string containing letters and punctuation from any language.

static static
timestamp()

Adds timestamp rule. Asserts that the input looks like a human timestamp, 24 or 12 hours format with or without seconds.

static static
timestamp12()

Adds timestamp.12 rule. Asserts that the input looks like a human timestamp, 12 hours format with or without seconds and optional AM/PM..

static static
timestampHm()

Adds timestamp.hm rule. Asserts that the input looks like a human timestamp, 24 or 12 hours format without seconds.

static static
timestampHms()

Adds timestamp.hms rule. Asserts that the input looks like a human timestamp, 24 or 12 hours format with seconds.

static static
timestampMs()

Adds timestamp.ms rule. Asserts that the input looks like a human timestamp, containing minutes and seconds only.

static static
timezone(bool $strict = false) Adds `timezone` rule. Asserts that the input is a valid timezone identifier (default: case-insensitive; strict: case-sensitive)

.

static static
type(string|array $type)

Adds type rule. Asserts that the input is one of the given types.

static static
typeDebug(string $type) Adds `type.debug` rule. Asserts that the input is of the given type using get_debug_type()

.

static static
upper()

Adds upper rule. Asserts that the input consists of uppercase characters only.

static static
url()

Adds url rule. Asserts that the input is a URL.

static static
urlWithPath()

Adds url.withPath rule. Asserts that the input is a URL that contains a path.

static static
urlWithQuery()

Adds url.withQuery rule. Asserts that the input is a URL that contains a query.

static static
username() $dds `username` rule. Asserts that the input is a valid username (between 4-32 characters, consists $f letters in any case, optionally $umbers, optionally $ne of the following characters "-_." (not consecutive), and $ust always start with a letter and end with a letter or number)

.

static static
uuid(string|int|null $version = null) Adds `uuid` rule. Asserts that the input is a valid UUID. The version (v1/v2/v3/v4/v5)

can be specifed to narrow the pattern.

static string
variable(string $key)

Returns a the passed key as a valid back-reference injectable.

static static
version()

Adds version rule. Asserts that the input is a valid semantic version number.

static static
vin() $dds `vin` rule. Asserts that the input is a valid VIN (Vehicle Identification Number)

.

static static
words()

Adds words rule. Asserts that the input is a string containing only words and spaces without any other character.

write(string $string)

Writes the passed string to the current expression string buffer.

static static
xdigit()

Adds xdigit rule. Asserts that the input represent hexadecimal digits.

static static
xml()

Adds xml rule. Asserts that the input is a valid XML.

xor()

Adds XOR operator (caret: ^). Xors the next rule/group.

Details

mixed __call(string $name, array $arguments)

Provides rules and aliases as class methods.

Parameters

string $name
array $arguments

Return Value

mixed

static mixed __callStatic(string $name, array $arguments)

Provides rules and aliases as static class methods.

Parameters

string $name
array $arguments

Return Value

mixed

__construct(Validator|null $validator = null)

Validation constructor.

Parameters

Validator|null $validator

[optional] The validator instance, used to retrieve available rules from. If not specified, rule name guessing as per convention will be used instead.

string __toString()

Returns the current expression string.

Return Value

string

static static accepted() $dds `accepted` rule. Asserts that the input is accepted (equals: "on", "aye" $, 1 $r "1", true $r "true")

note that strings are treated in a case-insensitive manner.

Parameters

) $dds `accepted` rule. Asserts that the input is accepted (equals: "on"
"aye" $
1 $r "1"
true $r "true"

Return Value

static

Validation add(Expression $validation)

Adds a validation string or object as a group to the current validation expression.

Parameters

Expression $validation

Validation expression string or object.

Return Value

Validation

static static allowed() $dds `allowed` rule. Asserts that the input is allowed (can be empty or have any value, null $nd empty string are considered valid values)

.

Parameters

) $dds `allowed` rule. Asserts that the input is allowed (can be empty or have any value
null $nd empty string are considered valid values

Return Value

static

static static alnum()

Adds alnum rule. Asserts that the input consists of alphanumeric characters only.

Return Value

static

static static alpha()

Adds alpha rule. Asserts that the input consists of alphabetic characters only.

Return Value

static

static static amount() $dds `amount` rule. Asserts that the input contains only numbers, an $ptional decimal point (comma or dot), and $n optional minus (used for amounts of money for example)

.

Parameters

) $dds `amount` rule. Asserts that the input contains only numbers
an $ptional decimal point (comma or dot)
and $n optional minus (used for amounts of money for example

Return Value

static

static static amountDollar()

Adds amount.dollar rule. Asserts that the input is a validly formatted amount of USD, where decimal point and thousands separator are optional.

Return Value

static

static static amountEuro()

Adds amount.euro rule. Asserts that the input is a validly formatted amount of EUR, where decimal point and thousands separator are optional.

Return Value

static

Expression and()

Adds AND operator (ampersand: &) (default). Ands the next rule/group.

Return Value

Expression

static static arr()

Adds arr rule. An alias for the array rule.

Return Value

static

static static array()

Adds array rule. Asserts that the input is an array.

Return Value

static

static static arrayHasDistinct(string|int $key)

Adds array.hasDistinct rule. Asserts that the input is a multidimensional array that contains distinct values of the given key.

Parameters

string|int $key

Return Value

static

static static arrayHasKey(string|int $key)

Adds array.hasKey rule. Asserts that the input array has the given key.

Parameters

string|int $key

Return Value

static

static static arrayHasValue(mixed $value)

Adds array.hasValue rule. Asserts that the input array contains the given value. Works with scalar types.

Parameters

mixed $value

Return Value

static

static static arrayIsAssociative()

Adds array.isAssociative rule. Asserts that the input is an associative array.

Return Value

static

static static arrayIsSequential()

Adds array.isSequential rule. Asserts that the input is a sequential array.

Return Value

static

static static arrayIsUnique()

Adds array.isUnique rule. Asserts that the input array contains unique values. Works only with one-dimensional arrays.

Return Value

static

static static arraySubset(array $subset)

Adds array.subset rule. Asserts that the input is an array that contains the given subset. Note that this check applies only to the first dimension of the array.

Parameters

array $subset

Return Value

static

static static ascii() $dds `ascii` rule. Asserts that the input is a string containing only ASCII characters (ASCII compliant string)

.

Parameters

) $dds `ascii` rule. Asserts that the input is a string containing only ASCII characters (ASCII compliant string

Return Value

static

static static assert(mixed $actual, mixed $expected = true, string $operator = '==')

Adds assert rule. An alias for the if rule.

Parameters

mixed $actual
mixed $expected
string $operator

Return Value

static

static static assertEquals(mixed $actual, mixed $expected)

Adds assert.equals rule. An alias for the if.eq rule.

Parameters

mixed $actual
mixed $expected

Return Value

static

static static assertGreaterThan(mixed $actual, mixed $expected)

Adds assert.greaterThan rule. An alias for the if.gt rule.

Parameters

mixed $actual
mixed $expected

Return Value

static

static static assertGreaterThanOrEquals(mixed $actual, mixed $expected)

Adds assert.greaterThanOrEquals rule. An alias for the if.gte rule.

Parameters

mixed $actual
mixed $expected

Return Value

static

static static assertLessThan(mixed $actual, mixed $expected)

Adds assert.lessThan rule. An alias for the if.lt rule.

Parameters

mixed $actual
mixed $expected

Return Value

static

static static assertLessThanOrEquals(mixed $actual, mixed $expected)

Adds assert.lessThanOrEquals rule. An alias for the if.lte rule.

Parameters

mixed $actual
mixed $expected

Return Value

static

static static assertNotEquals(mixed $actual, mixed $expected)

Adds assert.notEquals rule. An alias for the if.neq rule.

Parameters

mixed $actual
mixed $expected

Return Value

static

static static base64()

Adds base64 rule. Asserts that the input is a valid Base64 encoded string.

Return Value

static

static static between(int|float $min, int|float $max) Adds `between` rule. Asserts that the input count is between the given values. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count)

.

Parameters

int|float $min
int|float $max) Adds `between` rule. Asserts that the input count is between the given values. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count

Return Value

static

static static bic() $dds `bic` rule. Asserts that the input is a valid BIC (Bank Identifier Code)

.

Parameters

) $dds `bic` rule. Asserts that the input is a valid BIC (Bank Identifier Code

Return Value

static

static static bit() $dds `bit` rule. Asserts that the input is bit (equals: 1 or "1", true; $or "0", false $)

.

Parameters

) $dds `bit` rule. Asserts that the input is bit (equals: 1 or "1"
true; $or "0"
false $

Return Value

static

static static bitIsOff() $dds `bit.isOff` rule. Asserts that the input is a turned off bit (equals: false, $r "0")

.

Parameters

) $dds `bit.isOff` rule. Asserts that the input is a turned off bit (equals: false
$r "0"

Return Value

static

static static bitIsOn() $dds `bit.isOn` rule. Asserts that the input is a turned on bit (equals: true, 1 $r "1")

.

Parameters

) $dds `bit.isOn` rule. Asserts that the input is a turned on bit (equals: true
1 $r "1"

Return Value

static

static static blank()

Adds blank rule. An alias for the empty rule.

Return Value

static

static static bool()

Adds bool rule. An alias for the boolean rule.

Return Value

static

static static boolean()

Adds boolean rule. Asserts that the input is a boolean.

Return Value

static

static static booleanLike() $dds `booleanLike` rule. Asserts that the input is value that can be parsed as a boolean (TRUE: true, null $, "yes"; $ALSE: false)

.

Parameters

) $dds `booleanLike` rule. Asserts that the input is value that can be parsed as a boolean (TRUE: true
null $
"yes"; $ALSE: false

Return Value

static

string build()

Returns the current expression string.

Return Value

string

Exceptions

InvalidValidationExpressionException

static static cakeday()

Adds cakeday rule. An alias for the datetime.birthday rule.

Return Value

static

static static calenderDay() $dds `calender.day` rule. Asserts that the input looks like a calendar dayin shot or long format ("Mon" or "Monday")

.

Parameters

) $dds `calender.day` rule. Asserts that the input looks like a calendar dayin shot or long format ("Mon" or "Monday"

Return Value

static

static static calenderMonth() $dds `calender.month` rule. Asserts that the input looks like a calendar month in shot or long format ("Jan" or "January")

.

Parameters

) $dds `calender.month` rule. Asserts that the input looks like a calendar month in shot or long format ("Jan" or "January"

Return Value

static

static static callable()

Adds callable rule. Asserts that the input is a callable.

Return Value

static

Validation callback(callable $callback, string|null $id = null)

Writes a rule to the current validation expression that executes the passed callback.

Parameters

callable $callback

The callback to execute. The callback will be passed the current input as the first parameter and the rule object as the second parameter. It must return a boolean as result.

string|null $id

[optional] The callback id. The name (or a unique ID if not specified) will be prefixed with callback. to allow the possibility of providing a message for the callback on the Validator instance.

Return Value

Validation

Exceptions

ValidationLogicException

static static choice(string|int|float|bool|null $values)

Adds choice rule. An alias for the in rule.

Parameters

string|int|float|bool|null $values

Return Value

static

Expression close()

Adds CLOSE operator (closing parenthesis: )). Ends the current group.

Return Value

Expression

static static cntrl()

Adds cntrl rule. Asserts that the input consists of control characters only.

Return Value

static

static static color() $dds `color` rule. Asserts that the input is a valid CSS color (Color Word, HSLA $)

.

Parameters

) $dds `color` rule. Asserts that the input is a valid CSS color (Color Word
HSLA $

Return Value

static

static static colorHex()

Adds color.hex rule. Asserts that the input is a valid CSS HEX color.

Return Value

static

static static colorHexAlpha() $dds `color.hexAlpha` rule. Asserts that the input is a valid CSS HEX-Alpha (4 or 8 Chars)

color.

Parameters

) $dds `color.hexAlpha` rule. Asserts that the input is a valid CSS HEX-Alpha (4 or 8 Chars

Return Value

static

static static colorHexLong()

Adds color.hexLong rule. Asserts that the input is a valid CSS 6-Char-HEX color.

Return Value

static

static static colorHexShort()

Adds color.hexShort rule. Asserts that the input is a valid CSS 3-Char-HEX color.

Return Value

static

static static colorHsl()

Adds color.hsl rule. Asserts that the input is a valid CSS HSL color.

Return Value

static

static static colorHslNew()

Adds color.hsl.new rule. Asserts that the input is a valid CSS4 HSL color.

Return Value

static

static static colorHsla()

Adds color.hsla rule. Asserts that the input is a valid CSS HSLA color.

Return Value

static

static static colorKeyword()

Adds color.keyword rule. Asserts that the input is a valid CSS YYY color.

Return Value

static

static static colorRgb()

Adds color.rgb rule. Asserts that the input is a valid CSS RGB color.

Return Value

static

static static colorRgbNew()

Adds color.rgb.new rule. Asserts that the input is a valid CSS4 RGB color.

Return Value

static

static static colorRgba()

Adds color.rgba rule. Asserts that the input is a valid CSS RGBA color.

Return Value

static

static string comment(string $text)

Returns a the passed string as a valid comment.

Parameters

string $text

Comment text.

Return Value

string

A valid comment or an empty string if the passed parameter was empty.

NOTE: This method returns the passed string as a valid comment (∕*text*∕) only, and does NOT add it to the buffer, use self::concat() to add it.

Expression concat(string $string)

Writes the passed string to the current expression string buffer.

Note that the necessary operators will NOT be added automatically (use self::write() instead). Note that this method may make the expression fail when build if it is malformed.

Parameters

string $string

Rule, rule statement, rule alias, rule macro, an operator, a variable, a comment, or any arbitrary string.

Return Value

Expression

static static count(int $count) Adds `count` rule. Asserts that the input count is equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count)

.

Parameters

int $count) Adds `count` rule. Asserts that the input count is equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count

Return Value

static

static static countable()

Adds countable rule. Asserts that the input is a countable.

Return Value

static

static static country(bool $long = false) Adds `country` rule. Asserts that the input is a valid country code (default: "ISO 3166-1 alpha-2"; long: "ISO 3166-1 alpha-3")

.

Parameters

bool $long

Return Value

static

protected string createRuleStatement(string $name, array $arguments)

Returns a valid rule statement from the passed name and arguments.

Parameters

string $name

Rule name, preferably in camelCase.

array $arguments

Rule arguments.

Return Value

string

The rule statement.

static static creditcard()

Adds creditcard rule. Asserts that the input is a valid credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardAmericanExpress()

Adds creditcard.americanExpress rule. Asserts that the input is a valid American Express credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardChinaUnionPay()

Adds creditcard.chinaUnionPay rule. Asserts that the input is a valid China UnionPay credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardDinersClub()

Adds creditcard.dinersClub rule. Asserts that the input is a valid Diners Club credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardDiscover()

Adds creditcard.discover rule. Asserts that the input is a valid Discover credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardInstaPayment()

Adds creditcard.instaPayment rule. Asserts that the input is a valid InstaPayment credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardJcb()

Adds creditcard.jcb rule. Asserts that the input is a valid JCB credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardLaser()

Adds creditcard.laser rule. Asserts that the input is a valid Laser credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardMaestro()

Adds creditcard.maestro rule. Asserts that the input is a valid Maestro credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardMastercard()

Adds creditcard.mastercard rule. Asserts that the input is a valid Mastercard credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardMir()

Adds creditcard.mir rule. Asserts that the input is a valid MIR Payment System card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardUatp()

Adds creditcard.uatp rule. Asserts that the input is a valid UATP credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static creditcardVisa()

Adds creditcard.visa rule. Asserts that the input is a valid Visa credit card number, balanced spaces and/or dashes are allowed.

Return Value

static

static static currency(bool $numeric = false) Adds `currency` rule. Asserts that the input is a valid currency code (default: "ISO 4217 alpha"; numeric: "ISO 4217 numeric")

.

Parameters

bool $numeric

Return Value

static

static static currencyName() $dds `currency.name` rule. Asserts that the input is a valid currency name (as in ISO 4217)

.

Parameters

) $dds `currency.name` rule. Asserts that the input is a valid currency name (as in ISO 4217

Return Value

static

static static cvv() $dds `cvv` rule. Asserts that the input is a valid CVV (Card Security Code)

.

Parameters

) $dds `cvv` rule. Asserts that the input is a valid CVV (Card Security Code

Return Value

static

static static date()

Adds date rule. An alias for the datetime rule.

Return Value

static

static static dateAfter(string $datetime)

Adds date.after rule. An alias for the datetime.gt rule.

Parameters

string $datetime

Return Value

static

static static dateAfterOrEquals(string $datetime)

Adds date.afterOrEquals rule. An alias for the datetime.gte rule.

Parameters

string $datetime

Return Value

static

static static dateBefore(string $datetime)

Adds date.before rule. An alias for the datetime.lt rule.

Parameters

string $datetime

Return Value

static

static static dateBeforeOrEquals(string $datetime)

Adds date.beforeOrEquals rule. An alias for the datetime.lte rule.

Parameters

string $datetime

Return Value

static

static static dateEquals(string $datetime)

Adds date.equals rule. An alias for the datetime.eq rule.

Parameters

string $datetime

Return Value

static

static static dateFormat(string $format)

Adds date.format rule. An alias for the datetime.format rule.

Parameters

string $format

Return Value

static

static static datestamp()

Adds datestamp rule. Asserts that the input looks like a human datestamp, DMY or MDY format, separated with dot, dash, or slash.

Return Value

static

static static datestampDmy()

Adds datestamp.dmy rule. Asserts that the input looks like a human DMY-formatted datestamp, separated with dot, dash, or slash.

Return Value

static

static static datestampMdy()

Adds datestamp.mdy rule. Asserts that the input looks like a human MDY-formatted datestamp, separated with dot, dash, or slash.

Return Value

static

static static datestampYmd()

Adds datestamp.ymd rule. Asserts that the input looks like a human YMD-formatted datestamp, separated with dot, dash, or slash.

Return Value

static

static static datetime()

Adds datetime rule. Asserts that the input is a valid datetime string/object.

Return Value

static

static static datetimeBirthday()

Adds datetime.birthday rule. Asserts that the input is a datetime string/object that has birthday today. Input should preferably be in "YYYY-MM-DD" format.

Return Value

static

static static datetimeEq(string $datetime)

Adds datetime.eq rule. Asserts that the input is a datetime string/object equal to the given datetime string.

Parameters

string $datetime

Return Value

static

static static datetimeFormat(string $format)

Adds datetime.format rule. Asserts that the input is a valid datetime with the given format.

Parameters

string $format

Return Value

static

static static datetimeFormatGlobal()

Adds datetime.format.global rule. Asserts that the input looks like a valid global datetime string as defined in the HTML5 specification.

Return Value

static

static static datetimeFormatLocal()

Adds datetime.format.local rule. Asserts that the input looks like a valid local datetime string as defined in the HTML5 specification.

Return Value

static

static static datetimeGt(string $datetime) Adds `datetime.gt` rule. Asserts that the input is a datetime string/object greater than (after)

the given datetime string.

Parameters

string $datetime) Adds `datetime.gt` rule. Asserts that the input is a datetime string/object greater than (after

Return Value

static

static static datetimeGte(string $datetime) Adds `datetime.gte` rule. Asserts that the input is a datetime string/object greater than (after)

or equal to the given datetime string.

Parameters

string $datetime) Adds `datetime.gte` rule. Asserts that the input is a datetime string/object greater than (after

Return Value

static

static static datetimeLt(string $datetime) Adds `datetime.lt` rule. Asserts that the input is a datetime string/object less than (before)

the given datetime string.

Parameters

string $datetime) Adds `datetime.lt` rule. Asserts that the input is a datetime string/object less than (before

Return Value

static

static static datetimeLte(string $datetime) Adds `datetime.lte` rule. Asserts that the input is a datetime string/object less than (before)

or equal to the given datetime string.

Parameters

string $datetime) Adds `datetime.lte` rule. Asserts that the input is a datetime string/object less than (before

Return Value

static

static static declined() $dds `declined` rule. Asserts that the input is declined (equals: "off", "nay" $, $r "0", false $r "false")

note that strings are treated in a case-insensitive manner.

Parameters

) $dds `declined` rule. Asserts that the input is declined (equals: "off"
"nay" $
$r "0"
false $r "false"

Return Value

static

static static digit() $dds `digit` rule. Asserts that the input consists of a digits only (numeric characters)

.

Parameters

) $dds `digit` rule. Asserts that the input consists of a digits only (numeric characters

Return Value

static

static static domain()

Adds domain rule. Asserts that the input is a domain.

Return Value

static

static static domainIsActive()

Adds domain.isActive rule. Asserts that the input is an active domain. Works with domains and emails.

Return Value

static

static static double()

Adds double rule. An alias for the float rule.

Return Value

static

static static email()

Adds email rule. Asserts that the input is an email address.

Return Value

static

static static emailWithUnicode() $dds `email.withUnicode` rule. Asserts that the input is an email address (unicode allowed)

.

Parameters

) $dds `email.withUnicode` rule. Asserts that the input is an email address (unicode allowed

Return Value

static

static static emoji()

Adds emoji rule. Asserts that the input contains an emoji.

Return Value

static

static static empty() $dds `empty` rule. Asserts that the input is empty using empty() language construct (is blank, i.e. $mpty string, empty $rray, or $)

.

Parameters

) $dds `empty` rule. Asserts that the input is empty using empty() language construct (is blank
i.e. $mpty string
empty $rray
or $

Return Value

static

static static equals(string|int|float|bool|null $value)

Adds equals rule. Asserts that the input is equal to the given value. Works with scalar types and null. Comparison operator is "==".

Parameters

string|int|float|bool|null $value

Return Value

static

static static esn() $dds `esn` rule. Asserts that the input is a valid ESN (Electronic Serial Number)

.

Parameters

) $dds `esn` rule. Asserts that the input is a valid ESN (Electronic Serial Number

Return Value

static

static static file() $dds `file` rule. Asserts that the input is a file (can be a file, a $ink, or $directory)

.

Parameters

) $dds `file` rule. Asserts that the input is a file (can be a file
a $ink
or $directory

Return Value

static

static static fileBasename(string $basename)

Adds file.basename rule. Asserts that the input is a file and its basename is equal to the given basename.

Parameters

string $basename

Return Value

static

static static fileDirname(string $dirname)

Adds file.dirname rule. Asserts that the input is a file and its dirname is equal to the given dirname.

Parameters

string $dirname

Return Value

static

static static fileExtension(string $extension)

Adds file.extension rule. Asserts that the input is a file and its extension is equal to the given extension.

Parameters

string $extension

Return Value

static

static static fileFilename(string $filename)

Adds file.filename rule. Asserts that the input is a file and its filename is equal to the given filename.

Parameters

string $filename

Return Value

static

static static fileIsDirectory()

Adds file.isDirectory rule. Asserts that the input is a directory.

Return Value

static

static static fileIsExecutable()

Adds file.isExecutable rule. Asserts that the input is a file and is executable.

Return Value

static

static static fileIsFile()

Adds file.isFile rule. Asserts that the input is a file.

Return Value

static

Adds file.isLink rule. Asserts that the input is a link.

Return Value

static

static static fileIsReadable()

Adds file.isReadable rule. Asserts that the input is a file and is readable.

Return Value

static

static static fileIsUploaded()

Adds file.isUploaded rule. Asserts that the input is a file that is uploaded via HTTP POST.

Return Value

static

static static fileIsWritable()

Adds file.isWritable rule. Asserts that the input is a file and is writable.

Return Value

static

static static fileMime(string|array $mine)

Adds file.mime rule. Asserts that the input is a file and its MIME type is one of the given MIME types.

Parameters

string|array $mine

Return Value

static

static static fileSize(int $sizeInBytes)

Adds file.size rule. Asserts that the input is a file and the size is equal to the given size in bytes.

Parameters

int $sizeInBytes

Return Value

static

static static fileSizeGte(int $sizeInBytes)

Adds file.size.gte rule. Asserts that the input is a file and the size is greater than or equal to the given size in bytes.

Parameters

int $sizeInBytes

Return Value

static

static static fileSizeLte(int $sizeInBytes)

Adds file.size.lte rule. Asserts that the input is a file and the size is less than or equal to the given size in bytes.

Parameters

int $sizeInBytes

Return Value

static

static static filled()

Adds filled rule. An alias for the required rule.

Return Value

static

static static float()

Adds float rule. Asserts that the input is a float.

Return Value

static

static static floatLike(float $min = PHP_FLOAT_MIN, float $max = PHP_FLOAT_MAX)

Adds floatLike rule. Asserts that the input is a value that can be parsed as a float within the specifed range.

Parameters

float $min
float $max

Return Value

static

static static floatLikeAllowThousands(float $min = PHP_FLOAT_MIN, float $max = PHP_FLOAT_MAX)

Adds floatLike.allowThousands rule. Asserts that the input is a value that can be parsed as a float within the specifed range.

Parameters

float $min
float $max

Return Value

static

static static forbidden() $dds `forbidden` rule. Asserts that the input is forbidden (is null or not present)

.

Parameters

) $dds `forbidden` rule. Asserts that the input is forbidden (is null or not present

Return Value

static

static static geolocation() $dds `geolocation` rule. Asserts that the input is a valid geolocation (latitude and longitude coordinates combination)

.

Parameters

) $dds `geolocation` rule. Asserts that the input is a valid geolocation (latitude and longitude coordinates combination

Return Value

static

private string getBehaviorChars()

No description

Return Value

string

private string getHashedName(string $name)

Returns a consistent hash for the rule name.

Parameters

string $name

Rule name.

Return Value

string

private array getHashedNames()

Returns an associative array of rule names and their corresponding hashes.

Return Value

array

private array getOperatorChars()

No description

Return Value

array

static static graph() $dds `graph` rule. Asserts that the input consists of graphic characters only (characters that create a visible output)

.

Parameters

) $dds `graph` rule. Asserts that the input consists of graphic characters only (characters that create a visible output

Return Value

static

Expression group(callable $callback)

Groups a set of rules inside a pair of parentheses ().

Parameters

callable $callback

The callback that will be called to build the group. The callback will be bound to the current instance and/or receive it as the first parameter if can't be bound.

Return Value

Expression

static static iban(?string $country = null) Adds `iban` rule. Asserts that the input is a valid IBAN (International Bank Account Number)

. The "ISO 3166-1 alpha-2" country code can be specifed to narrow the pattern.

Parameters

?string $country

Return Value

static

static static if(mixed $actual, mixed $expected = true, string $operator = '==')

Adds if rule. Checks the condition between the first argument and the second argument, the condition operator can also be specified as the third argument.

Parameters

mixed $actual
mixed $expected
string $operator

Return Value

static

static static ifEq(mixed $actual, mixed $expected)

Adds if.eq rule. Checks the condition between the first argument and the second argument, the condition operator is "==".

Parameters

mixed $actual
mixed $expected

Return Value

static

static static ifGt(mixed $actual, mixed $expected)

Adds if.gt rule. Checks the condition between the first argument and the second argument, the condition operator is ">".

Parameters

mixed $actual
mixed $expected

Return Value

static

static static ifGte(mixed $actual, mixed $expected)

Adds if.gte rule. Checks the condition between the first argument and the second argument, the condition operator is ">=".

Parameters

mixed $actual
mixed $expected

Return Value

static

static static ifId(mixed $actual, mixed $expected)

Adds if.id rule. Checks the condition between the first argument and the second argument, the condition operator is "===".

Parameters

mixed $actual
mixed $expected

Return Value

static

static static ifLt(mixed $actual, mixed $expected)

Adds if.lt rule. Checks the condition between the first argument and the second argument, the condition operator is "<".

Parameters

mixed $actual
mixed $expected

Return Value

static

static static ifLte(mixed $actual, mixed $expected)

Adds if.lte rule. Checks the condition between the first argument and the second argument, the condition operator is "<=".

Parameters

mixed $actual
mixed $expected

Return Value

static

static static ifNeq(mixed $actual, mixed $expected)

Adds if.neq rule. Checks the condition between the first argument and the second argument, the condition operator is "!=".

Parameters

mixed $actual
mixed $expected

Return Value

static

static static ifNid(mixed $actual, mixed $expected)

Adds if.nid rule. Checks the condition between the first argument and the second argument, the condition operator is "!==".

Parameters

mixed $actual
mixed $expected

Return Value

static

static static image() $dds `image` rule. Asserts that the input is an image file (jpg, svg $, or $ebp)

.

Parameters

) $dds `image` rule. Asserts that the input is an image file (jpg
svg $
or $ebp

Return Value

static

static static imageDimensions(int $width, int $height, string $operator = '==')

Adds image.dimensions rule. Asserts that the input is an image and its dimensions are less than, equal to, or greater than the given width and height in pixels.

Parameters

int $width
int $height
string $operator

Return Value

static

static static imageHeight(int $height)

Adds image.height rule. Asserts that the input is an image and its height is equal to the given height in pixels.

Parameters

int $height

Return Value

static

static static imageHeightGte(int $height)

Adds image.height.gte rule. Asserts that the input is an image and its height is greater than or equal to the given height in pixels.

Parameters

int $height

Return Value

static

static static imageHeightLte(int $height)

Adds image.height.lte rule. Asserts that the input is an image and its height is less than or equal to the given height in pixels.

Parameters

int $height

Return Value

static

static static imageRatio(string $ratio) Adds `image.ratio` rule. Asserts that the input is an image and its aspect ratio is equal to the given ratio (ratio must be specified like "16:9")

.

Parameters

string $ratio) Adds `image.ratio` rule. Asserts that the input is an image and its aspect ratio is equal to the given ratio (ratio must be specified like "16:9"

Return Value

static

static static imageWidth(int $width)

Adds image.width rule. Asserts that the input is an image and its width is equal to the given width in pixels.

Parameters

int $width

Return Value

static

static static imageWidthGte(int $width)

Adds image.width.gte rule. Asserts that the input is an image and its width is greater than or equal to the given width in pixels.

Parameters

int $width

Return Value

static

static static imageWidthLte(int $width)

Adds image.width.lte rule. Asserts that the input is an image and its width is less than or equal to the given width in pixels.

Parameters

int $width

Return Value

static

static static imei() $dds `imei` rule. Asserts that the input is a valid IMEI (International Mobile Station Equipment Identity Number)

.

Parameters

) $dds `imei` rule. Asserts that the input is a valid IMEI (International Mobile Station Equipment Identity Number

Return Value

static

static static imeiSv() $dds `imei.sv` rule. Asserts that the input is a valid IMEI-SV (International Mobile Station Equipment Identity and Software Version Number)

.

Parameters

) $dds `imei.sv` rule. Asserts that the input is a valid IMEI-SV (International Mobile Station Equipment Identity and Software Version Number

Return Value

static

static static in(string|int|float|bool|null $values)

Adds in rule. Asserts that the input is in the given values. Works with scalar types and null.

Parameters

string|int|float|bool|null $values

Return Value

static

static static int()

Adds int rule. An alias for the integer rule.

Return Value

static

static static integer()

Adds integer rule. Asserts that the input is an integer.

Return Value

static

static static integerLike(int $min = PHP_INT_MIN, int $max = PHP_INT_MAX)

Adds integerLike rule. Asserts that the input is a value that can be parsed as an integer within the specifed range.

Parameters

int $min
int $max

Return Value

static

static static integerLikeAllowHex(int $min = PHP_INT_MIN, int $max = PHP_INT_MAX)

Adds integerLike.allowHex rule. Asserts that the input is a value that can be parsed as an integer within the specifed range and can be in hexadecimal notation.

Parameters

int $min
int $max

Return Value

static

static static integerLikeAllowOctal(int $min = PHP_INT_MIN, int $max = PHP_INT_MAX)

Adds integerLike.allowOctal rule. Asserts that the input is a value that can be parsed as an integer within the specifed range and can be in octal notation.

Parameters

int $min
int $max

Return Value

static

static static ip()

Adds ip rule. Asserts that the input is an IP address.

Return Value

static

static static ipNotPrivate()

Adds ip.notPrivate rule. Asserts that the input is an IP address not within private IPs range.

Return Value

static

static static ipNotReserved()

Adds ip.notReserved rule. Asserts that the input is an IP address not within reserved IPs range.

Return Value

static

static static ipV4()

Adds ip.v4 rule. Asserts that the input is an IPv4 address.

Return Value

static

static static ipV6()

Adds ip.v6 rule. Asserts that the input is an IPv6 address.

Return Value

static

static static is(mixed $value)

Adds is rule. An alias for the equals rule.

Parameters

mixed $value

Return Value

static

static static isbn(string|int|null $type = null) Adds `isbn` rule. Asserts that the input is a valid ISBN (International Standard Book Number). The type (10/13)

can be specifed to narrow the pattern.

Parameters

string|int|null $type

Return Value

static

static static isin() $dds `isin` rule. Asserts that the input is a valid ISIN (International Securities Identification Number)

.

Parameters

) $dds `isin` rule. Asserts that the input is a valid ISIN (International Securities Identification Number

Return Value

static

static static issn() $dds `issn` rule. Asserts that the input is a valid ISSN (International Standard Serial Number)

.

Parameters

) $dds `issn` rule. Asserts that the input is a valid ISSN (International Standard Serial Number

Return Value

static

static static iterable()

Adds iterable rule. Asserts that the input is an iterable.

Return Value

static

static static json()

Adds json rule. Asserts that the input is a valid JSON.

Return Value

static

static static language(bool $long = false) Adds `language` rule. Asserts that the input is a valid language code (default: "ISO 639-1"; long: "ISO 639-2/T")

.

Parameters

bool $long

Return Value

static

static static length(int $count)

Adds length rule. An alias for the count rule.

Parameters

int $count

Return Value

static

static static locale(bool $strict = false) Adds `locale` rule. Asserts that the input is a valid locale identifier (default: [ISO 639-1] or [ISO 639-1]_[ISO 3166-1 alpha-2], case-insensitive $, input $s canonicalized before checking (dashes to underscores, no $ots or charset)

; strict: [ISO 639-1] or [ISO 639-1]_[ISO 3166-1 alpha-2], case-sensitive without canonicalization.

Parameters

bool $strict
case-insensitive $
input $s canonicalized before checking (dashes to underscores
no $ots or charset

Return Value

static

static static long()

Adds long rule. An alias for the integer rule.

Return Value

static

static static lower()

Adds lower rule. Asserts that the input consists of lowercase characters only.

Return Value

static

static static luhn()

Adds luhn rule. Asserts that the input passes the Luhn Algorithm check. This rule is mostly used in conjunction with other rules like credit card numbers and identifiers to further check the validity of the subject.

Return Value

static

static static mac()

Adds mac rule. Asserts that the input is a MAC address.

Return Value

static

Expression macro(string $macro)

Writes a macro to the current expression string.

Parameters

string $macro

Macro name (without []).

Return Value

Expression

static static matches(string $pattern)

Adds matches rule. Asserts that the input matches the given pattern. Works with strings only.

Parameters

string $pattern

Return Value

static

static static max(int|float $count) Adds `max` rule. Asserts that the input count is less than or equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count)

.

Parameters

int|float $count) Adds `max` rule. Asserts that the input count is less than or equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count

Return Value

static

static static meid() $dds `meid` rule. Asserts that the input is a valid MEID (Mobile Equipment Identifier)

.

Parameters

) $dds `meid` rule. Asserts that the input is a valid MEID (Mobile Equipment Identifier

Return Value

static

static static meta() $dds `meta` rule. Asserts that the input is a string containing only meta characters (special characters) (i.e. "@, ..." $)

.

Parameters

) $dds `meta` rule. Asserts that the input is a string containing only meta characters (special characters) (i.e. "@
..." $

Return Value

static

static static min(int|float $count) Adds `min` rule. Asserts that the input count is greater than or equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count)

.

Parameters

int|float $count) Adds `min` rule. Asserts that the input count is greater than or equal to the given value. Works with all data types (null: 0; boolean: 0 or 1; float/integer: number value; string: characters count; array/countable: elements count; object: accessible properties count

Return Value

static

static static minmax(int|float $min, int|float $max)

Adds minmax rule. An alias for the between rule.

Parameters

int|float $min
int|float $max

Return Value

static

static Validation new()

Creates a new Validation instance that is bound to the default Validator.

Return Value

Validation

static static nino() $dds `nino` rule. Asserts that the input is a valid NINO (UK National Insurance Number)

.

Parameters

) $dds `nino` rule. Asserts that the input is a valid NINO (UK National Insurance Number

Return Value

static

Expression normal()

Makes the expression normal (executes all checks). The is the default behavior.

NOTE: Use this to remove an already added behavior.

Return Value

Expression

Expression not()

Adds NOT operator (tilde: ~). Negates the next rule/group.

Return Value

Expression

static static null()

Adds null rule. Asserts that the input is null.

Return Value

static

static static numberIsEven()

Adds number.isEven rule. Asserts that the input is an even number.

Return Value

static

static static numberIsFinite()

Adds number.isFinite rule. Asserts that the input is a finite number.

Return Value

static

static static numberIsInfinite()

Adds number.isInfinite rule. Asserts that the input is an infinite number.

Return Value

static

static static numberIsMultipleOf(float $number)

Adds number.isMultipleOf rule. Asserts that the input is a multiple of the given number.

Parameters

float $number

Return Value

static

static static numberIsNan()

Adds number.isNan rule. Asserts that the input is a not a number.

Return Value

static

static static numberIsNegative()

Adds number.isNegative rule. Asserts that the input is a negative number.

Return Value

static

static static numberIsOdd()

Adds number.isOdd rule. Asserts that the input is an odd number.

Return Value

static

static static numberIsPositive()

Adds number.isPositive rule. Asserts that the input is a positive number.

Return Value

static

static static numeric()

Adds numeric rule. Asserts that the input is numeric.

Return Value

static

static static obj()

Adds obj rule. An alias for the object rule.

Return Value

static

static static object()

Adds object rule. Asserts that the input is an object.

Return Value

static

static static objectHasMethod(string $method)

Adds object.hasMethod rule. Asserts that the input has the given method.

Parameters

string $method

Return Value

static

static static objectHasProperty(string $property)

Adds object.hasProperty rule. Asserts that the input has the given property.

Parameters

string $property

Return Value

static

static static objectIsInstanceOf(string $classFQN)

Adds object.isInstanceOf rule. Asserts that the input is an instance of the given class.

Parameters

string $classFQN

Return Value

static

static static objectIsStringable() $dds `object.isStringable` rule. Asserts that the input implements __toString()

method.

Parameters

) $dds `object.isStringable` rule. Asserts that the input implements __toString(

Return Value

static

static static objectIsSubclassOf(string $classFQN)

Adds object.isSubclassOf rule. Asserts that the input is a subclass of the given class.

Parameters

string $classFQN

Return Value

static

Expression open()

Adds OPEN operator (opening parenthesis: (). Starts a new group.

Return Value

Expression

Expression optimistic()

Makes the expression optimistic (stop checking after first success).

NOTE: This has effect only if the expression is not already PESSIMISTIC.

NOTE: Be careful when using OPTIMISTIC with AND or XOR.

Return Value

Expression

static static optional()

Adds optional rule. An alias for the allowed rule.

Return Value

static

Expression or()

Adds OR operator (pipe: |). Ors the next rule/group.

Return Value

Expression

static static password() $dds `password` rule. Asserts that the input is a valid password (minimum 8 characters, consists $f at least one small letter and one capital letter, at $east one number, at $east one special character, and $ptionally a space)

.

Parameters

) $dds `password` rule. Asserts that the input is a valid password (minimum 8 characters
consists $f at least one small letter and one capital letter
at $east one number
at $east one special character
and $ptionally a space

Return Value

static

static static pattern(string $pattern)

Adds pattern rule. An alias for the matches rule.

Parameters

string $pattern

Return Value

static

Expression pessimistic()

Makes the expression pessimistic (stop checking after first failure).

NOTE: This has effect only if the expression is not already PESSIMISTIC.

NOTE: Be careful when using PESSIMISTIC with OR or XOR.

Return Value

Expression

static static phone() $dds `phone` rule. Asserts that the input is a valid phone number (supports: North America, Europe $nd most Asian and Middle East countries)

.

Parameters

) $dds `phone` rule. Asserts that the input is a valid phone number (supports: North America
Europe $nd most Asian and Middle East countries

Return Value

static

static static phpKeyword()

Adds php.keyword rule. Asserts that the input is a PHP language Keyword.

Return Value

static

static static phpReserved()

Adds php.reserved rule. Asserts that the input is a PHP language reserved word.

Return Value

static

static static phpReservedExtra()

Adds php.reserved.extra rule. Asserts that the input is a PHP language reserved word including soft reserved words.

Return Value

static

static static present()

Adds present rule. An alias for the required rule.

Return Value

static

static static print()

Adds print rule. Asserts that the input consists of printable characters only.

Return Value

static

static static punct()

Adds punct rule. Asserts that the input consists of punctuation characters only.

Return Value

static

static static range(int|float $min, int|float $max)

Adds range rule. An alias for the between rule.

Parameters

int|float $min
int|float $max

Return Value

static

static static real()

Adds real rule. An alias for the float rule.

Return Value

static

static static regex()

Adds regex rule. Asserts that the input is a valid regular expression.

Aliases:

Return Value

static

static static regexp(string $pattern)

Adds regexp rule. Asserts that the input matches a Perl-compatible regular expression.

Parameters

string $pattern

Return Value

static

static static required() $dds `required` rule. Asserts that the input is required (is not blank, i.e. $ot a empty string or null)

.

Parameters

) $dds `required` rule. Asserts that the input is required (is not blank
i.e. $ot a empty string or null

Return Value

static

static static resource()

Adds resource rule. Asserts that the input is a resource.

Return Value

static

static static roman()

Adds roman rule. Asserts that the input is a valid roman number.

Return Value

static

Expression rule(string $rule)

Writes a rule to the current expression string.

Parameters

string $rule

Rule statement (or rule alias).

Return Value

Expression

static static same(mixed $value)

Adds same rule. An alias for the equals rule.

Parameters

mixed $value

Return Value

static

static static scalar()

Adds scalar rule. Asserts that the input is a scalar.

Return Value

static

static static serialized()

Adds serialized rule. Asserts that the input is a valid PHP serialized data.

Return Value

static

static static sin() $dds `sin` rule. Asserts that the input is a valid SIN (CA Social Insurance Number)

.

Parameters

) $dds `sin` rule. Asserts that the input is a valid SIN (CA Social Insurance Number

Return Value

static

static static size(int $size)

Adds size rule. An alias for the count rule.

Parameters

int $size

Return Value

static

static static slug()

Adds slug rule. Asserts that the input is a valid slug.

Return Value

static

static static space()

Adds space rule. Asserts that the input consists of whitespace characters only.

Return Value

static

static static spaceless()

Adds spaceless rule. Asserts that the input is a string containing no whitespace characters.

Return Value

static

static static ssn() $dds `ssn` rule. Asserts that the input is a valid SSN (Social Security Number)

.

Parameters

) $dds `ssn` rule. Asserts that the input is a valid SSN (Social Security Number

Return Value

static

static static str()

Adds str rule. An alias for the string rule.

Return Value

static

static static stream()

Adds stream rule. An alias for the resource rule.

Return Value

static

static static string()

Adds string rule. Asserts that the input is a string.

Return Value

static

static static stringCharset(string|array $charset) Adds `string.charset` rule. Asserts that the input is encoded in one of the given charsets (aliases included)

. The check is done in a case-sensitive manner.

Parameters

string|array $charset) Adds `string.charset` rule. Asserts that the input is encoded in one of the given charsets (aliases included

Return Value

static

static static stringContains(string $substring, bool $strict = false) Adds `string.contains` rule. Asserts that the input contains the given substring. A second boolean argument can be specified to enable strict mode (case-sensitive)

.

Parameters

string $substring
bool $strict

Return Value

static

static static stringEndsWith(string $substring, bool $strict = false) Adds `string.endsWith` rule. Asserts that the input ends with the given substring. A second boolean argument can be specified to enable strict mode (case-sensitive)

.

Parameters

string $substring
bool $strict

Return Value

static

static static stringLength(int $length)

Adds string.length rule. Asserts that the input is a string that is exactly the given length.

Parameters

int $length

Return Value

static

static static stringStartsWith(string $substring, bool $strict = false) Adds `string.startsWith` rule. Asserts that the input starts with the given substring. A second boolean argument can be specified to enable strict mode (case-sensitive)

.

Parameters

string $substring
bool $strict

Return Value

static

static static stringWordsCount(int $count)

Adds string.wordsCount rule. Asserts that the input is a string containing exactly the given count of words.

Parameters

int $count

Return Value

static

static static text()

Adds text rule. Asserts that the input is a string containing letters and punctuation from any language.

Return Value

static

static static timestamp()

Adds timestamp rule. Asserts that the input looks like a human timestamp, 24 or 12 hours format with or without seconds.

Return Value

static

static static timestamp12()

Adds timestamp.12 rule. Asserts that the input looks like a human timestamp, 12 hours format with or without seconds and optional AM/PM..

Return Value

static

static static timestampHm()

Adds timestamp.hm rule. Asserts that the input looks like a human timestamp, 24 or 12 hours format without seconds.

Return Value

static

static static timestampHms()

Adds timestamp.hms rule. Asserts that the input looks like a human timestamp, 24 or 12 hours format with seconds.

Return Value

static

static static timestampMs()

Adds timestamp.ms rule. Asserts that the input looks like a human timestamp, containing minutes and seconds only.

Return Value

static

static static timezone(bool $strict = false) Adds `timezone` rule. Asserts that the input is a valid timezone identifier (default: case-insensitive; strict: case-sensitive)

.

Parameters

bool $strict

Return Value

static

static static type(string|array $type)

Adds type rule. Asserts that the input is one of the given types.

Parameters

string|array $type

Return Value

static

static static typeDebug(string $type) Adds `type.debug` rule. Asserts that the input is of the given type using get_debug_type()

.

Parameters

string $type) Adds `type.debug` rule. Asserts that the input is of the given type using get_debug_type(

Return Value

static

static static upper()

Adds upper rule. Asserts that the input consists of uppercase characters only.

Return Value

static

static static url()

Adds url rule. Asserts that the input is a URL.

Return Value

static

static static urlWithPath()

Adds url.withPath rule. Asserts that the input is a URL that contains a path.

Return Value

static

static static urlWithQuery()

Adds url.withQuery rule. Asserts that the input is a URL that contains a query.

Return Value

static

static static username() $dds `username` rule. Asserts that the input is a valid username (between 4-32 characters, consists $f letters in any case, optionally $umbers, optionally $ne of the following characters "-_." (not consecutive), and $ust always start with a letter and end with a letter or number)

.

Parameters

) $dds `username` rule. Asserts that the input is a valid username (between 4-32 characters
consists $f letters in any case
optionally $umbers
optionally $ne of the following characters "-_." (not consecutive)
and $ust always start with a letter and end with a letter or number

Return Value

static

static static uuid(string|int|null $version = null) Adds `uuid` rule. Asserts that the input is a valid UUID. The version (v1/v2/v3/v4/v5)

can be specifed to narrow the pattern.

Parameters

string|int|null $version

Return Value

static

static string variable(string $key)

Returns a the passed key as a valid back-reference injectable.

Parameters

string $key

Variable key (without $}).

Return Value

string

A valid back-reference or an empty string if the passed parameter was empty.

NOTE: This method returns the passed key as a valid back-reference (${key}) only, and NOT the actual value of the variable and does NOT add it to the buffer.

static static version()

Adds version rule. Asserts that the input is a valid semantic version number.

Return Value

static

static static vin() $dds `vin` rule. Asserts that the input is a valid VIN (Vehicle Identification Number)

.

Parameters

) $dds `vin` rule. Asserts that the input is a valid VIN (Vehicle Identification Number

Return Value

static

static static words()

Adds words rule. Asserts that the input is a string containing only words and spaces without any other character.

Return Value

static

Expression write(string $string)

Writes the passed string to the current expression string buffer.

Note that the necessary operators will be added automatically.

Parameters

string $string

Rule, rule statement, rule alias, rule macro or an operator.

Return Value

Expression

static static xdigit()

Adds xdigit rule. Asserts that the input represent hexadecimal digits.

Return Value

static

static static xml()

Adds xml rule. Asserts that the input is a valid XML.

Return Value

static

Expression xor()

Adds XOR operator (caret: ^). Xors the next rule/group.

Return Value

Expression