View Full Version : Need Email Validation and Captcha

05-22-2012, 02:40 PM

When I have email validation and captcha in the same form, simply passing the captcha allows the form to be sent without an email address. When I remove the captcha, the form will not send without the email address. I want to have both. What am I missing?



function validateForm()
var x=document.forms["WebsiteQuestion"]["Email"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
alert("Not a valid e-mail address");
return false;

function clearForms()
var i;
for (i = 0; (i < document.forms.length); i++) {

<div align="center">
<script language="javascript" src="http://www.captcha.cc/cap.js?cap_k=tocsoLPahVjmEHJZWtenaJEDoJXfrQaa" type="text/javascript">
<input type=hidden name=cap_h id=cap_h value="">
<img border=1 id=cap_i src="http://www.captcha.cc/img.cgi?cap_k=tocsoLPahVjmEHJZWtenaJEDoJXfrQaa" align=middle><img align=middle style="margin-left: 4px;" id=cap_r onload="return cap_showReload(event);" src="http://www.captcha.cc/blank.png"><br>
<input id=cap_t name=cap_t type=text value="" style="margin-top:4px;">
<input type=submit value="Submit Form" onclick="return cap_valid(event);">

I appreciate any help. Thank you, Elbee

Philip M
05-22-2012, 03:22 PM
You probably have multiple onload statements. In which case the second script will over-write the first.

Your email validation is long obsolete. Use this regex instead:-

if (!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@((\w)([\w\-]?)+\.)+([a-z]{2,4})$/i.test(x))) { // returns true if invalid

If you want to allow for the very rare travel and museum domains, change {2,4} to {2,6}. If you want to allow for French lawyers change it to {2,7}.

But in fact as most errors in emai addresses are typos etc. which cannot be detected the best email check is to request the user to enter his adddress twice, and compare the two for equality.

Quizmaster: What name is shared by rivers in Russia and in South Yorkshire?
Contestant: The Tiber