Validator
class Validator (View source)
Constants
| MODE_STOP |
|
| MODE_THROW |
|
Methods
No description
Configures failure messages of standard rules.
Rules can be a string separated by | or an array
(use an array for regex: rules, since patterns may contain |).
Returns True if there are no failures; otherwise, returns False
Returns all error messages
Get an instance of an extended rule
Details
__construct(array $data, $mode = 0)
No description
static Validator
get(int $mode = 0)
Create a Validator instance using $_GET
static Validator
post(int $mode = 0)
Create a Validator instance using $_POST
Validator
setMessage(string $type, string $message)
Configures failure messages of standard rules.
Note: To customize the messages for additional rules, use the getRuleInstance() method.
Validator
setRule(string $name, string $rule)
Set a new rule or overwrite an existing rule
Validator
field(string $path, mixed $var, string|array $rules, mixed $default = null)
Rules can be a string separated by | or an array
(use an array for regex: rules, since patterns may contain |).
Supported rules:
- boolean (On, Yes, True, 1, Off, No, False, and 0)
- decimal (if valid convert to float)
- equals:
- email (validates only the format)
- in:<a,b,c> (unexpected value)
- integer (if valid convert to int)
- max:
(value for decimal and int; length for strings) - min:
(value for decimal and int; length for strings) - regex:
(not match with the expected format) - required (is required)
- url (a valid url)
bool
valid()
Returns True if there are no failures; otherwise, returns False
array<string, string>
failures()
Returns all error messages
Rule
getRuleInstance($rule)
Get an instance of an extended rule