I have a requirement where in a request containing field comes in to my rest webservice.
In my webservice, I have to check for this field and if the validation for this passes, then I send the request to a third party service.
Validation Required:
message_from field contains an email address as string. I have to check if the domain name(everything after @) is roin.com
For ex: abc@roin.com passes, john_mandoza@roin.com passes, john_manodza@google.com fails…
Can I use pattern matchers or anything else to do this validation?
I have used string parsing to capture everything after (@) and then did an equalsIgnoreCase to compare it with roin.com
This string parsing approach works, but is there any better way to do this?
You can try this pattern
(\\S+?@roin\\.com): –\\S+is used to match any non-space character?after\\S+is used to do reluctant matching. It will match least number of character to satisfy the pattern\\.is used to match..is a special character in Regex, that is why we need to escape it to match it as literal.So, here’s the code: –