Skip to content

Can't use "pipe" in Validators pattern #206

Closed

Description

@TomPavelec

Version: v3.0.1

Bug Description

Can not use "pipe" ("|") character in Validators pattern

Steps To Reproduce

Validators::is('a', 'pattern:(a|b)');
// E_WARNING: preg_match(): Compilation failed: missing closing parenthesis at offset 1

Expected Behavior

Validators::is('a', 'pattern:(a|b)');
// should return true

Activity

  1. dg commented on Dec 3, 2019

    @dg
    Member

    Related #14 #15 #31

    It is really hard to fix.

  2. dg commented on Oct 28, 2026

    @dg
    Member

    Thanks for the report, and thanks to @dualfroz for the attempt in #340. The problem is real, but I've decided not to fix it in Validators.

    The | in the type expression is the separator of alternatives, so a pattern containing it can only be supported by special-casing pattern:, which changes the meaning of existing expressions such as pattern:\d+|email. Validators is a legacy part of Utils now; its role is being taken over by nette/schema, where the pattern is passed on its own and the pipe works as expected:

    Expect::string()->pattern('a|b')

    So I'm closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions