We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Allow email validator null values

Someone can guide me to allow just null emails or correct ones? Phalcon 3, PHP7

My code:

public function validation()
{
    $validator = new Validation();

    $validator->add(
        'email',
        new EmailValidator()
    );
    return $this->validate($validator);
}


40.0k
Accepted
answer

use:

'allowEmpty' => true

example:

$validator->add(
        'email',
        new EmailValidator([
            'allowEmpty' => true
        ])
    );

Got it! Concise and clear, best regards!