简体   繁体   English

Phalcon Regex验证密码不起作用

[英]Phalcon Regex validation password doesn't work

I don't understand why my Regex doesn't work. 我不明白为什么我的Regex不起作用。 There is always an error message for any passwords. 任何密码始终都会出现错误消息。

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

The error is : 0 or 4 char minimum. 错误是:最少0或4个字符。

Just combine the StringLenght validation with the allowEmpty option: 只需将StringLenght验证与allowEmpty选项结合起来allowEmpty

$badPassMessage = 'Define a password using exactly 4 characters or leave it empty!';
$validation->add('password', new StringLength(array(
      'max' => 4,
      'min' => 4,
      'allowEmpty' => true,
      'messageMaximum' => $badPassMessage,
      'messageMinimum' => $badPassMessage
)));
BONUS 奖金

I'd recommend you to always test your patterns with this excellent tool: 我建议您始终使用此出色的工具测试模式:

regular expressions 101 正则表达式101

Always make sure that the regex flavor is set to pcre (php) . 始终确保将正则表达式的pcre (php)设置为pcre (php)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM