I want a regex pattern to allow a mailto: link to have multiple email address
I tried below pattern:
"((href|src)(\\S)*?=(\\S)*?)?(\"|'|)(((mailto:)?(?:[A-Z0-9._-])@(?:[A-Z0-9.-])\\.[A-Z]([,;]\\s*(?:[A-Z0-9._-])@(?:[A-Z0-9.-])\\.[A-Z])*(</a>)?))"
example:
<a href = mailto:abc@abc.com,sdf@abc.com>mail me</a>;
Is this regex pattern correct?
Short answer – no. There are valid email addresses that it will filter out. For just a single example,
+is a completely valid character in the local part of an email address (and an important one for many people) which you’re going to reject.Longer answer – no, and you’re not going to write a regex that is "correct" in the technical sense (of conforming to RFC 5322). Local parts can have almost any characters in them as they’re interpreted by the target mailserver; they can also be enclosed in quotes. The best approach is not to use regex for this at all but use a decent third-party validator.