验证类
API - Core_Valid
- Valid::not_empty - Checks if a field is not empty.
- Valid::regex - Checks a field against a regular expression.
- Valid::min_length - Checks that a field is long enough.
- Valid::max_length - Checks that a field is short enough.
- Valid::exact_length - Checks that a field is exactly the right length.
- Valid::equals - Checks that a field is exactly the value required.
- Valid::email - Check an email address for correct format.
- Valid::email_domain - Validate the domain of an email address by checking if the domain has a
- Valid::url - Validate a URL.
- Valid::ip - Validate an IP.
- Valid::credit_card - Validates a credit card number, with a Luhn check if possible.
- Valid::luhn - Validate a number against the [Luhn](http://en.wikipedia.org/wiki/Luhn_algorithm)
- Valid::date - Tests if a string is a valid date string.
- Valid::alpha - Checks whether a string consists of alphabetical characters only.
- Valid::alpha_numeric - Checks whether a string consists of alphabetical characters and numbers only.
- Valid::alpha_dash - Checks whether a string consists of alphabetical characters, numbers, underscores and dashes only.
- Valid::digit - Checks whether a string consists of digits only (no dots or dashes).
- Valid::numeric - Checks whether a string is a valid number (negative and decimal numbers allowed).
- Valid::range - Tests if a number is within a range.
- Valid::decimal - Checks if a string is a proper decimal format. Optionally, a specific
- Valid::color - Checks if a string is a proper hexadecimal HTML color value. The validation
- Valid::matches - Checks if a field matches the value of another field.
Checks if a field is not empty.
boolean
Checks a field against a regular expression.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
Value | |
$expression |
string |
Regular expression to match (including delimiters) |
boolean
Checks that a field is long enough.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
Value | |
$length |
integer |
Minimum length required |
boolean
Checks that a field is short enough.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
Value | |
$length |
integer |
Maximum length required |
boolean
Checks that a field is exactly the right length.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
Value | |
$length |
integer |
Exact length required |
boolean
Checks that a field is exactly the value required.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$value |
string |
Value | |
$required |
string |
Required value |
boolean
Check an email address for correct format.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$email |
string |
Email address | |
$strict |
boolean |
Strict RFC compatibility | bool false |
boolean
Validate the domain of an email address by checking if the domain has a valid MX record.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$email |
string |
Email address |
boolean
Validate a URL.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$url |
string |
URL |
boolean
Validate an IP.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$ip |
string |
IP address | |
$allow_private |
boolean |
Allow private IP networks | bool true |
boolean
Validates a credit card number, with a Luhn check if possible.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$number |
integer |
Credit card number | |
$type |
string|array |
Card type, or an array of card types | null |
boolean
Validate a number against the Luhn (mod10) formula.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$number |
string |
Number to check |
boolean
Tests if a string is a valid date string.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Date to check |
boolean
Checks whether a string consists of alphabetical characters only.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Input string | |
$utf8 |
boolean |
Trigger UTF-8 compatibility | bool false |
boolean
Checks whether a string consists of alphabetical characters and numbers only.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Input string | |
$utf8 |
boolean |
Trigger UTF-8 compatibility | bool false |
boolean
Checks whether a string consists of alphabetical characters, numbers, underscores and dashes only.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Input string | |
$utf8 |
boolean |
Trigger UTF-8 compatibility | bool false |
boolean
Checks whether a string consists of digits only (no dots or dashes).
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Input string | |
$utf8 |
boolean |
Trigger UTF-8 compatibility | bool false |
boolean
Checks whether a string is a valid number (negative and decimal numbers allowed).
Uses {@link http://www.php.net/manual/en/function.localeconv.php locale conversion} to allow decimal point to be locale specific.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Input string |
boolean
Tests if a number is within a range.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$number |
string |
Number to check | |
$min |
integer |
Minimum value | |
$max |
integer |
Maximum value |
boolean
Checks if a string is a proper decimal format. Optionally, a specific number of digits can be checked too.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Number to check | |
$places |
integer |
Number of decimal places | integer 2 |
$digits |
integer |
Number of digits | null |
boolean
Checks if a string is a proper hexadecimal HTML color value. The validation is quite flexible as it does not require an initial "#" and also allows for the short notation using only three instead of six hexadecimal characters.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$str |
string |
Input string |
boolean
Checks if a field matches the value of another field.
参数 | 类型 | 描述 | 默认值 |
---|---|---|---|
$array |
array |
Array of values | |
$field |
string |
Field name | |
$match |
string |
Field name to match |
boolean