Is it possible to validate that a Character is either M or F or do I need to use a string with a regex?
@Pattern(regexp = \"^[MF]{1}$\", message = \"custome
Your should this regular expression for accepting only M or F.
@Pattern(regexp = "^[M|F]{1}$", message ="Must be M or F")
In your second case of using as Character, you need to validate that this character is whether "M" or "F". Other can be set as sex.
You cannot use @Pattern
for Character
variable, You will get below exception.
javax.validation.UnexpectedTypeException: HV000030: No validator could be found for type: java.lang.Character.