Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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.3k
Accepted
answer

Add the parameter allowEmpty to the validator, ex:

<?php

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