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.

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

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