String emailRegex = '([a-zA-Z0-9_\\-\\.]+)@((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})';
Pattern MyPattern = Pattern.compile(emailRegex);
// Then instantiate a new Matcher object "MyMatcher"
String InputString ='abc@xyzzzz.com';
Matcher MyMatcher = MyPattern.matcher(InputString);
if (!MyMatcher.matches()) {
// invalid, do something
System.debug('Invalid Email Addresss');
}
else
{
System.debug('Valid Email Addresss');
}
Pattern MyPattern = Pattern.compile(emailRegex);
// Then instantiate a new Matcher object "MyMatcher"
String InputString ='abc@xyzzzz.com';
Matcher MyMatcher = MyPattern.matcher(InputString);
if (!MyMatcher.matches()) {
// invalid, do something
System.debug('Invalid Email Addresss');
}
else
{
System.debug('Valid Email Addresss');
}
Does not work when email starts with two dots, i.e. "..lastname@somewhere.com".
ReplyDeleteRegex says "valid", salesforce says "invalid"
Please check How to Check email address is valid in apex post.
Deletehttps://apexin3hands.blogspot.in/2015/09/how-to-check-email-address-is-valid-in.html?m=1
DeleteThank you again for all the knowledge you distribute,Good post. I was very interested in the article, it's quite inspiring I should admit. I like visiting you site since I always come across interesting articles like this one.Great Job, I greatly appreciate that.Do Keep sharing! Regards, verifications.io
ReplyDelete