简体   繁体   English

Symfony 验证错误:preg_match():编译失败:字符 class 在偏移处的范围乱序

[英]Symfony Validation error: preg_match(): Compilation failed: range out of order in character class at offset

When I was verifying the operation of the app that was updated from Symfony 2.x to Symfony 4.4, the following error occurred.当我验证从 Symfony 2.x 更新到 Symfony 4.4 的应用程序的操作时,出现以下错误。
The function I was verifying was to enter the id "."我正在验证的 function 是输入 id “。” To be validated and verify that the validation works correctly, Half-width alphanumeric characters, underscores (_), hyphens (-).要进行验证并验证验证是否正常工作,半角字母数字字符、下划线 (_)、连字符 (-)。 and dots (.) Can be used in the target area.和点 (.) 可用于目标区域。
Is there anything you can think of?有什么你能想到的吗?
I deleted form.errors, but it didn't work.我删除了 form.errors,但它没有用。

Error错误

preg_match(): Compilation failed: range out of order in character class at offset 13

Type类型

                $form->add("loginId", TextType::class, array(
                   "required" => false,
                ));

         $resolver->setDefaults(array(
             'validation_groups' => function (FormInterface $form) {
                 $options = $form->getConfig()->getOptions();
                 $loginStaff = $options["login_staff"];
                 $staff = $form->getData();
                 return $this->getValidationGroups($loginStaff, $staff);
             },
         ));
     private function getValidationGroups($loginStaff, $staff)
     {
         $validationGroups = array();
         if ($loginStaff->isManage()) {
             $validationGroups[] = 'manage';
         }
 
         if ($loginStaff->isHq()) {
             if ($staff->getPassword()) {
                 $validationGroups[] = 'hqEdit';
             } else {
                 $validationGroups[] = 'hqNew';
             }
         } else {
             if ($staff->getPassword()) {
                 $validationGroups[] = 'shopEdit';
             } else {
                 $validationGroups[] = 'shopNew';
             }
         }
 
         return $validationGroups;
     }

validation.yaml验证.yaml

    getters:      
        loginId: 
            - Length: { max: 20, groups: [hqInitialSetting, shopInitialSetting, hqEdit, shopEdit] } 
            - Regex:        
                pattern: "/^[a-zA-Z0-9_-.]+$/" 
                groups: [hqInitialSetting, shopInitialSetting, hqEdit, shopEdit]

Staff.php职员.php

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use AppBundle\Model\Lib\Parameters;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\UserInterface;
 /**
 *
 * @ORM\Entity(repositoryClass="AppBundle\Model\Repository\StaffRepository")
 * @ORM\Table(name="staff", uniqueConstraints={
 *      @ORM\UniqueConstraint(name="idx_staff_unique", columns={"staff_login_id"}),
 *      @ORM\UniqueConstraint(name="idx_image_mail_unique", columns={"image_mail"})
 * })
 * @ORM\HasLifecycleCallbacks
 */
class Staff implements AdvancedUserInterface, \Serializable, EquatableInterface
{
    /**
     * @ORM\Column(name="login_id", type="string", length=20, nullable=true, options={"comment"="ID"})
     */
    protected $loginId;

twig twig

    {{ form_start(form) }}

        {{ form_errors(form) }}
            <div class="formGroup">
                <div class="formGroup">
                    {{ form_label(form.loginId, 'LOGIN ID') }}
                    {{ form_widget(form.loginId) }}
                    {{ form_errors(form.loginId) }}
                </div>
        </div>
        {{ form_rest(form) }}
    {{ form_end(form) }}

I changed the regex and it worked fine.我更改了正则表达式,它工作正常。
The regular expression method may have changed due to the php version upgrade.由于 php 版本升级,正则表达式方法可能发生了变化。

pattern: "/^[a-zA-Z0-9-_.]+$/" 

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

相关问题 preg_match():编译失败:偏移处的字符类范围无效 - preg_match(): Compilation failed: invalid range in character class at offset preg_match_all 编译失败:字符类在偏移量处的范围乱序 - preg_match_all Compilation failed: range out of order in character class at offset 对于字符类,preg_match错误:编译失败:缺少终止] - preg_match error: Compilation failed: missing terminating ] for character class 编译失败:字符类在偏移量12处范围混乱 - Compilation failed: range out of order in character class at offset 12 preg_match():编译失败:缺少字符类的终止符] - preg_match(): Compilation failed: missing terminating ] for character class preg_match():编译失败:字符无法识别 - preg_match(): Compilation failed: unrecognized character 警告:preg_split()[function.preg-split]:编译失败:字符类中的范围乱序 - Warning: preg_split() [function.preg-split]: Compilation failed: range out of order in character class preg_match给出编译失败错误 - preg_match gives compilation failed error preg_match():编译失败:\\ x {}或\\ o {}中的字符值在第25行的偏移27处太大 - preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 27 on line number 25 preg_match():编译失败:在偏移量2处无法重复 - preg_match(): Compilation failed: nothing to repeat at offset 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM