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.

Phalcon\Validation\Validator\Regex doesn't work

Hi,

I don't understand why my Regex doesn't work. There is always a error message for any passwords.

     $this->add('password', new RegexValidator(array(
               'pattern' => '.{0}|.{4,}',
               'message' => '0 or 4 char minimum'
     )));


14.0k
Accepted
answer

Problem solved. I'm using now the StringLength class with the 'allowEmpty' parameter :).

     $this->add('password', new StringLength(array(
        'min' => 4,
        'messageMinimum' => '4 char minimum',
        'allowEmpty' => true
     )));


64.2k

just if you didnt know this website. ( sorry if you do )

https://regex101.com/r/uU7iO9/1 its explain on the right



14.0k

Yes I know this website. But the problem wasn't is in my regex because in my view this regex works well. But server side there is a bug with the pattern attribute.

You have to use a PCRE compatible regex: "pattern" => "/.{0}|.{4,}/",



14.0k

Ok Thanks Andres. I'll try this next time if I have to use the Regex class.