📅  最后修改于: 2020-10-26 05:17:27             🧑  作者: Mango
通常在制作网站时,我们需要先验证某些内容,然后再进一步处理数据。 CakePHP提供了验证包,以构建可以轻松验证数据的验证器。
CakePHP在Validation类中提供了各种验证方法。下面列出了其中一些最受欢迎的内容。
Syntax |
Add(string $field, array|string $name, array|Cake\Validation\ValidationRule $rule [] ) |
---|---|
Parameters |
|
Returns |
$this |
Description |
Adds a new rule to a field’s rule set. If second argument is an array, then rules list for the field will be replaced with second argument and third argument will be ignored. |
Syntax |
allowEmpty(string $field, boolean|string|callable $whentrue, string|null $messagenull) |
---|---|
Parameters |
|
Returns | $this |
Description |
Allows a field to be empty. |
Syntax |
alphanumeric (string $field, string|null $messagenull, string|callable|null $whennull) |
Parameters |
|
Returns |
$this |
Description |
Add an alphanumeric rule to a field. |
Syntax |
creditCard(string $field , string $type‘all’, string|null $messagenull, string|callable|null $whennull) |
---|---|
Parameters |
|
Returns |
$this |
Description |
Add a credit card rule to a field. |
Syntax |
Email(string $field , boolean $checkMXfalse, string|null $messagenull, string|callable|null, $whennull) |
---|---|
Parameters |
|
Returns |
$this |
Description |
Add an email validation rule to a field. |
Syntax |
maxLength(string $field, integer $max, string|null $messagenull, string|callable|null $whennull) |
---|---|
Parameters |
|
Returns |
$this |
Description |
Add a string length validation rule to a field. |
Syntax |
minLength(string $field, integer $min, string|null $messagenull, string|callable|null $whennull) |
---|---|
Parameters |
|
Returns |
$this |
Description |
Add a string length validation rule to a field. |
Syntax |
notBlank(string $field, string|null $messagenull, string|callable|null $whennull) |
---|---|
Parameters |
|
Returns |
$this |
Description |
Add a notBlank rule to a field. |