Extract Email Addresses | JavaScriptSource

Extract Email Addresses

Ronnie Moore Sep 9, 2000
Visitors sometimes include their email address inside the message field when they fill out forms. To deal with this, this script parses through the string and uses a Regular Expression to find then return a comma-separated list of the valid email addresses it finds. Easy!

(For this demo, enter some text in the box and then click out of the field. If you included
one or more valid email addresses, they will be displayed in the Email field below the box.)


The JavaScript Source: Forms: Extract Email Addresses

Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s). The script is yours!!!


Did you use this script?  Do you like this site?  Please link to us!

Leave a Response

1 comment)

StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);[br /][br /]Technically, there are several more valid characters that should included in this regular expression.[br /][br /]According to RFC 2822 (URL below), all of the following US-ASCII characters are valid in the local part (before the "@") of an email address:[br /][br /]A-Z[br /]a-z[br /]0-9[br /]!#$%&'*+-/=?^_`{|}~[br /][br /]All of those except the dot character (.) are valid anywhere in the email address. The dot character may not appear as the first or last character in the local-part or domain.[br /][br /]http://www.faqs.org/rfcs/rfc2822.html[br /]See section 3.4.1. for the definition of "addr-spec", and section 3.2.4 for the definition of "atext".[br /][br /]At the very least, I think the plus symbol (+) should be included. It is used by popular mail services (including GMail and FastMail) to support customized email addresses.

jfinlayson Nov 25, 2008