Regex example

return $this->systemConfigService->getBool('core.newsletter.doubleOptInRegistered', $context->getSalesChannelId());
    }

    private function getOptInValidator(DataBag $dataBag, SalesChannelContext $context, bool $validateStorefrontUrl): DataValidationDefinition
    {
        $definition = new DataValidationDefinition('newsletter_recipient.create');
        $definition->add('email', new NotBlank()new Email())
            ->add('option', new NotBlank()new Choice(array_keys($this->getOptionSelection($context))));

        if (!empty($dataBag->get('firstName'))) {
            $definition->add('firstName', new NotBlank()new Regex([
                'pattern' => self::DOMAIN_NAME_REGEX,
                'match' => false,
            ]));
        }

        if (!empty($dataBag->get('lastName'))) {
            $definition->add('lastName', new NotBlank()new Regex([
                'pattern' => self::DOMAIN_NAME_REGEX,
                'match' => false,
            ]));
        }

        
$this->from = $this->extractTime($this->fromTime, $now);
        $this->to = $this->extractTime($this->toTime, $now);

        $this->switchValidationIfToIsSmallerThanFrom();

        return $this->returnResultWithSightOnValidationTurnover($now);
    }

    public function getConstraints(): array
    {
        return [
            'toTime' => [new NotBlank()new Regex(self::TIME_REGEX)],
            'fromTime' => [new NotBlank()new Regex(self::TIME_REGEX)],
        ];
    }

    private function extractTime(string $time, \DateTimeImmutable $now): \DateTimeInterface
    {
        [$hour$minute] = explode(':', $time);

        return $now->setTime((int) $hour(int) $minute);
    }

    


    private function createContactFormValidation(string $validationName, SalesChannelContext $context): DataValidationDefinition
    {
        $definition = new DataValidationDefinition($validationName);

        $definition
            ->add('salutationId', new NotBlank()new EntityExists(['entity' => 'salutation', 'context' => $context->getContext()]))
            ->add('email', new NotBlank()new Email())
            ->add('subject', new NotBlank())
            ->add('comment', new NotBlank())
            ->add('firstName', new Regex(['pattern' => self::DOMAIN_NAME_REGEX, 'match' => false]))
            ->add('lastName', new Regex(['pattern' => self::DOMAIN_NAME_REGEX, 'match' => false]));

        $required = $this->systemConfigService->get('core.basicInformation.firstNameFieldRequired', $context->getSalesChannel()->getId());
        if ($required) {
            $definition->set('firstName', new NotBlank()new Regex([
                'pattern' => self::DOMAIN_NAME_REGEX,
                'match' => false,
            ]));
        }

        $required = $this->systemConfigService->get('core.basicInformation.lastNameFieldRequired', $context->getSalesChannel()->getId());
        
yield 'subscribe with no correct validation' => [
            [
                'email' => 'test@example.com',
                'option' => 'direct',
                'firstName' => 'Y http://localhost',
                'lastName' => 'Tran http://localhost',
                'salutationId' => Uuid::randomHex(),
            ],
            ['firstName' => 'Y http://localhost', 'lastName' => 'Tran http://localhost'],
            [
                new NotBlank(),
                new Regex([
                    'pattern' => ContactFormValidationFactory::DOMAIN_NAME_REGEX,
                    'match' => false,
                ]),
            ],
        ];

        yield 'subscribe correct is validation' => [
            [
                'email' => 'test@example.com',
                'option' => 'direct',
                'firstName' => 'Y',
                
function DDataValidationDefinition $definition, SalesChannelContext $context): void {
                static::assertEquals($definition->getProperties()[
                    'salutationId' => [
                        new NotBlank(),
                        new EntityExists(['entity' => 'salutation', 'context' => $context->getContext()]),
                    ],
                    'email' => [new NotBlank()new Email()],
                    'subject' => [new NotBlank()],
                    'comment' => [new NotBlank()],
                    'firstName' => [
                        new NotBlank(),
                        new Regex(['pattern' => ContactFormValidationFactory::DOMAIN_NAME_REGEX, 'match' => false]),
                    ],
                    'lastName' => [
                        new NotBlank(),
                        new Regex(['pattern' => ContactFormValidationFactory::DOMAIN_NAME_REGEX, 'match' => false]),
                    ],
                    'phone' => [new NotBlank()],
                ]);
            },
        ];

        yield 'is not required' => [
            

        yield 'subscribe with no correct validation' => [
            [
                'email' => 'test@example.com',
                'option' => 'direct',
                'firstName' => 'Y http://localhost',
                'lastName' => 'Tran http://localhost',
            ],
            ['firstName' => 'Y http://localhost', 'lastName' => 'Tran http://localhost'],
            [
                new NotBlank(),
                new Regex([
                    'pattern' => NewsletterSubscribeRoute::DOMAIN_NAME_REGEX,
                    'match' => false,
                ]),
            ],
        ];

        yield 'subscribe correct is validation' => [
            [
                'email' => 'test@example.com',
                'option' => 'direct',
                'firstName' => 'Y',
                


        if ($this->config->get('shopSalutationRequired')) {
            $builder->add('salutation', SalutationType::class[
                'constraints' => [new NotBlank(['message' => null])],
            ]);
        }

        $builder->add('title', TextType::class);

        $builder->add('firstname', TextType::class[
            'constraints' => [new NotBlank(['message' => null])new Regex([
                'pattern' => self::DOMAIN_NAME_REGEX,
                'match' => false,
                'message' => $this->getSnippet(self::SNIPPET_URL),
            ])],
        ]);

        $builder->add('lastname', TextType::class[
            'constraints' => [new NotBlank(['message' => null])new Regex([
                'pattern' => self::DOMAIN_NAME_REGEX,
                'match' => false,
                'message' => $this->getSnippet(self::SNIPPET_URL),
            ])],
Home | Imprint | This part of the site doesn't use cookies.