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

Reges Validator Not Working

use Phalcon\Validation\Validator\Regex;

$contactNo = new Text('contactno');
$contactNo->setLabel('Vendor Contact Number');
$contactNo->addValidator(array(
    new Regex(array(
        'pattern' => '/^[789]\d{9}$/',
        'message' => 'The Contact Number is not valid'
    ))
));
$this->add($contactNo);

What is wrong in this code?

It's giving me error as "The validators parameter must be an object"



6.4k
Accepted
answer

Should be $contactNo->addValidator(new Regex(/* ... */)) or $contactNo->addValidators([new Regex(/* ... */), /* ... */])