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

check validator only if value present

How to validate only if value present in form element if there is class for form and validators are in form class



6.4k
Accepted
answer

Add the parameter allowEmpty to the validator, ex:

<?php

$element->addValidator(new Regex([
    'allowEmpty' => TRUE,
    'pattern'    => '/^\d{2}:\d{2}$/'
]));