2

I'm working on a Symfony2.0 form with a text field. I use Annotation to validate the field. The field has the following validation:

 * @Assert\MinLength(limit=2, message="At least two characters")
 * @Assert\NotBlank()
 * @Assert\Regex(
 *           pattern= "/\d/",
 *           match=   false,
 *           message= "This text cannot contain numbers" 
 * ) 

Notice that the Regex assertion comes from here.

So, I expect that all the characters except the numbers can be used! However, When I put some special chars like "ò", the form is not validated and the error message "This text cannot contain numbers" is returned.

I checked the Regex string at http://www.regextester.com/ and seems to work right!

Any idea why that validation in Symfony2.0 works bad? Am I missing something?

1 Answer 1

2

I changed the Regex proposed on the Symfony2.0 official doc as follows:

 @Assert\Regex(pattern= "/[0-9]/")

and now the form works well.

A final thought! I really don't understand why such characters are meant to be digits by using the Regex \d. Many non-English words use that characters.

Sign up to request clarification or add additional context in comments.

1 Comment

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.