I have an object called User and I want to check the mobile number field
The mobile number field is optional, you can leave it blank, but it must be a ten-digit number.
If the user enters any value less than 10 digits in length, then an error should be thrown.
Below is my User class.
public class User {
@Size(min=0,max=10)
private String mobileNo;
}
When I used the @Size annotation, as mentioned above, I could check values greater than 10, but if the user entered less than 10 digits, no error occurred.
My requirement: if the user left the mobileNo field empty, but if a value is entered, then the check should ensure that the entered number will consist of only 10 digits and 10 digits.
?