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.
(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.)
Add the below code to the <body> section of your page:
<scriptlanguage="javascript"type="text/javascript"> /* Visit http://www.yaldex.com/
for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin function
findEmailAddresses(StrObj){ var
separateEmailsBy =", "; var
email ="<none>";// if no match, use this var
emailsArray =
StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi); if(emailsArray){ email =""; for(var
i =0;
i <
emailsArray.length;
i++){ if(i
!=0)
email +=
separateEmailsBy; email +=
emailsArray[i]; } } return
email;
} // End --> </script> (For this demo, enter some text in the
box and then click out of the field. If you included<br> one or more valid email addresses, they
will be displayed in the Email field below the box.)<BR> <form><textareaname=commentsrows=10cols=50onBlur="this.form.email.value=findEmailAddresses(this.value);"></textarea> <br> Email:
<input
type=textname=email>
</form>