【发布时间】:2017-10-10 14:58:49
【问题描述】:
我想自定义用户密码的验证器。我对此进行了测试:
http://sylius-try.readthedocs.io/en/latest/bundles/general/overriding_validation.html
http://sylius-older.readthedocs.io/en/latest/customization/validation.html
http://docs.sylius.org/en/latest/customization/validation.html
但它对我不起作用。这是我的代码:
#AppBundle/Resources/config/validation.yml
Sylius\Bundle\UserBundle\Form\Model\ChangePassword:
properties:
currentPassword:
- Symfony\Component\Security\Core\Validator\Constraints\UserPassword:
message: sylius.user.plainPassword.wrong_current
groups: [myGroup]
newPassword:
- Regex:
pattern: ((?=\S*?[A-Z])(?=\S*?[a-z]).{8,})
message: myGroup.user.password.regex
groups: [myGroup]
配置:
#app/config/config.yml
imports:
- { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" }
Services.yml:
# app/config/services.yml
parameters:
sylius.form.type.user_change_password: [myGroup]
sylius.form.type.user_reset_password.validation_groups: [myGroup] # the product class also needs to be aware of the translation'a validation
问题是当我尝试更改密码或注册时,未检测到正则表达式。我确信它可以工作,因为当我更改文件 ChangePassword.yml 时,一切正常。但我无法接触到供应商的文件。
感谢您的宝贵时间
【问题讨论】:
-
好吧,您的正则表达式可能无法按预期工作。试试
^(?=.*?[A-Z])(?=.*?[a-z]).{8,}$或者因为它是 PHP -/^(?=.*?[A-Z])(?=.*?[a-z]).{8,}$/ -
正则表达式是正确的,我在vendor上试过,我在网上试过,不是这个问题。问题是 Sylius 没有找到覆盖文件
标签: php regex symfony validation sylius