Reputation: 89
Please refer to the below controller code:-
@GetMapping("/fetch)
void fetchData( @RequestParam
@Pattern(regexp="(^$|[0-9]{10})",message = "Mobile number must be 10 digits")
String mobileNumber)
{
.........//some functionality
}
Now if I call the above API:-
http://localhost:8080/fetch?mobileNumber=123456789
I am getting the error message:- Mobile Number must be 10 digits.
But If I hit the same API with empty mobile Number, the pattern validation is not working and it is proceeding in to the method. so If I call the below endpoint:-
http://localhost:8080/fetch?mobileNumber=
The validation is not working and I am not getting the error message.
Can you please tell me what is the issue, why is the error message not triggering for the second request? Am I missing something related to Regex?
Upvotes: 0
Views: 36