【问题标题】:Symfony form NumberType: This value is not validSymfony 表单 NumberType:此值无效
【发布时间】:2016-08-27 18:51:18
【问题描述】:

我有一个 NumberType 字段:

    ->add('numero', NumberType::class, [
        'required' => true,
        'attr' => [
            'placeholder' => "Numéro de la carte",
        ],
        'constraints' => [
            new Assert\NotBlank(['message' => "Ce champ est obligatoire."]),
            new Assert\Regex([
                'pattern' => '/^[0-9]{16}$/',
                'match'   => true,
                'message' => 'Le numéro de la carte doit être une suite de 16 chiffres.',
            ]),
        ]
    ])

正如我的正则表达式所说,一组 16 个数字是必需的。但我总是收到超过 7 个数字的“此值无效”消息。我不知道为什么。

【问题讨论】:

  • 到目前为止您尝试过哪些号码?

标签: forms symfony silex


【解决方案1】:

您应该将 NumberType::class 更改为 TextType:class,它应该可以正常工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-26
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 2018-03-01
    相关资源
    最近更新 更多