4

I have problem with javax.validation.constraints.Pattern @Pattern validation.

@Pattern(regexp = "\\p{L}*", message = "Msg")
private String name;

When I'm trying to input any text it doesn't work.

When I used:

@Pattern(regexp = "[a-zA-Z]*", message = "Msg")

It works great with non latin characters.

Tomasz Gutkowski
  • 1,388
  • 4
  • 20
  • 28

1 Answers1

1

You need to make the \p{L} pattern Unicode aware with the Pattern.UNICODE_CHARACTER_CLASS flag.

Enables the Unicode version of Predefined character classes and POSIX character classes.

Since you are using the string pattern, you may use the inline (embedded) flag variant, (?U):

regexp = "(?U)\\p{L}*"
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563