|
↑
Forms >>>
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:
<script
language="javascript"
type="text/javascript">
function
findEmailAddresses(StrObj)
{
var
separateEmailsBy =
", ";
var
email =
"<none>";
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;
}
</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><textarea
name=comments
rows=10
cols=50
onBlur="this.form.email.value=findEmailAddresses(this.value);"></textarea>
<br>
Email:
<input
type=text
name=email>
</form>
|
→
|