1

I am using bean validation to validate my entity, it works fine according to different locales and it shows region-specific error messages, but I want to internationalize a field 'ContactNo' according to the region like my error messages @NotBlank(message="{contactNo.size}").

So how to achieve

@Pattern(regexp="(^$|[0-9]{10})")
private String contactNo;`

where the regexp value changes according to the region?

1 Answers1

1

The the value for the regexp attribute has to be constant i.e. it needs to be available at compile time. So, either it needs to be a string literal as you do now or externalized into a static final variable.

I guess what you need has to be implemented in a custom Bean Validation constraint.

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198