Phalcon\Validation\Validator\Alpha work have aquestion
$validator = new \Phalcon\Validation();
$validator->add(
"username",
new \Phalcon\Validation\Validator\Alpha(
[
"message" => ":field must contain only letters",
'allowEmpty' =>false,
]
)
);
$data = ['username' =>'1'];
$message = $validator ->validate( $data );
it will output username must contain only letters ,but if $data have no the username index or the value is empty. the $message will return emty array. the correct validate result should't be fail?
You need to use Phalcon\Validation\Validator\PresenceOf for the field to be required
You need to use
Phalcon\Validation\Validator\PresenceOffor the field to be required
I have set allowEmpty be false, if use\Phalcon\Validation\Validator\Alnum,it will work。
What version of Phalcon are you using?
3.4.3
allowEmpty by default false (https://github.com/phalcon/cphalcon/blob/3.4.x/phalcon/validation.zep#L592) and should be used for setting to true or array
Alpha validation use preg_match preg_match("/[^[:alpha:]]/imu", value), try set value as empty string or null. (https://github.com/phalcon/cphalcon/blob/3.4.x/phalcon/validation/validator/alpha.zep#L73)
Different validation types can have different behavior if data key is empty string or null.
So, for correct validation "not empty", use PresenceOf , as @ekmst said.
We only accept bug reports, new feature requests and pull requests in GitHub. For questions regarding the usage of the framework, support requests, and questions like this please visit the official forums.