0

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?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
Roshan
  • 2,019
  • 8
  • 36
  • 56
  • Please put 4 spaces before code so that it will be properly escaped and monotyped. That will make it easier for people to read. – kerkeslager Jun 23 '10 at 10:49
  • Your example is missing an end-quote. Is this intentional? – lc. Jun 23 '10 at 10:49
  • 3
    Very similar to this post: http://stackoverflow.com/questions/201323/what-is-the-best-regular-expression-for-validating-email-addresses – Xetius Jun 23 '10 at 10:49
  • Check out a previous post on tools for validating RegEx... they are EXTREMELY useful! :) http://stackoverflow.com/questions/1965037/any-tools-for-creating-not-just-checking-regex – Alex Jun 23 '10 at 10:57
  • You might want to look at http://stackoverflow.com/questions/156430/regexp-recognition-of-email-address-hard for some example regexps. – Noufal Ibrahim Jun 23 '10 at 11:01

2 Answers2

0

Validating multiple emails this way could be a overkill. Check this http://forums.sun.com/thread.jspa?threadID=5427060&tstart=45 In case the emails are going to be from the same domain it can be simplified further.

user372993
  • 358
  • 2
  • 10
0

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.

Community
  • 1
  • 1
Andrzej Doyle
  • 102,507
  • 33
  • 189
  • 228