1

I have a problem displaying a custom message with Regex assert. It worked good for any other assert but not Regex.

Here is my assert :

@Assert\Regex(
 *     pattern = "/^[0-9]{1,6}(\.[0-9]{1,2})?$/"),
 *     message = "I want to display Bad value"
 * )

The validation works but the message is a symfony default one. Why is that ? What do I miss ?

Thank you

1 Answer 1

1

From what I see you have a bracket in wrong position. try:

* @Assert\Regex(
*     pattern = "/^[0-9]{1,6}(\.[0-9]{1,2})?$/",
*     message = "I want to display Bad value"
* )
Sign up to request clarification or add additional context in comments.

2 Comments

sorry I did not copy everything.. I have the last bracket of course
You still have one bracket too much, there is no need for bracket after pattern = "/^[0-9]{1,6}(\.[0-9]{1,2})?$/",

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.