2

I have a form field that I want to match the following rules: at least 3 numbers then at least 7 a-z or A-Z letters, currently I have this but it does not work apparently because I get that my input is not valid even if I respect the rule I mentioned :

->add('NumberAcc', TextType::class, [
            'constraints' => [
                new NotBlank(),
                new Regex('/[0-9]{3,},[a-z]{7,}/')
            ],
        ])

Any ideas? (I know it wont work with Maj letters right now but it doesn't work either with lowercase letters

3
  • 012,abcdefg matches. Is the comma in the middle a mistake or on purpose? Also, if you want to match uppercase letters too, include A-Z or make it case insensitive. (/[0-9]{3,}[a-z]{7,}/i) Commented Mar 14, 2018 at 8:27
  • 1
    Add your test case. Commented Mar 14, 2018 at 8:29
  • You cannot use Regex for that. My guess is you want a1b2c3d4e5... to be valid as well. Better use Callback constraint then. Commented Mar 14, 2018 at 8:32

1 Answer 1

5

Your regex contains a comma , between the numbers and the letters, which is not in the description of what you are trying to do. Also, if you want to capture both a-z and A-Z you have to explicitly specify it

/[0-9]{3,}[a-zA-Z]{7,}/

or make the regex case insensitive

/[0-9]{3,}[a-z]{7,}/i
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.