I have the following regexp that I am using to validate an email;
@Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid Email")
private String email;
My problem is that I can't seem to get the message from my ValidationMessage.properties file. It simply displays the string I place in the "". I tried the following:
message="{InvalidEmail}"
(there is a key pair called 'InvalidEmail' in the ValidationMessage.properties file) but instead of collection the key pair value it simply prints out the string '{InvalidEmail}'.
I can't seem to get the message from my ValidationMessage.properties file
The filename must be exactly ValidationMessages.properties
, with the plural s
. It must also be placed in the root of the classpath and thus not in any subfolder/package.
In case you actually wanted to customize the default name/location of the properties file, then you need to head to implementation specific ways, because this is not (yet?) supported by the API. In case of Hibernate Validator refer to section 4.2.1 ResourceBundleLocator.