tags:

views:

107

answers:

2

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:[email protected],[email protected]>mail me</a>;

Is this regex pattern correct?

A: 

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

A: 

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.

Andrzej Doyle