I have a class that represents form submit:
Class Form {
// @String(message = "Invalid type")
private String name;
}
I was looking for a javax.validation
annotation to put on top of the name
field, that will validate that the field is indeed of type string, and if not, display an appropriate error message, but I couldn't find one. What's the way to do it?
Clarification:
What bothers me is a case where someone sends one of the following payloads, and I still haven't seen a solution for that:
{
name: true
}
or
{
name: 1234
}
If you want to validate the input to only have alphabets then use @javax.validation.constraints.Pattern
like follows.
class Form {
@Pattern(regexp="^[A-Za-z]*$",message = "Invalid Input")
private String name;
}
This will validate that name will only have alphabet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With