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

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'
     )));


41.3k
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
     )));


85.5k

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

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

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,}/",

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