...

View Full Version : confirm email field javascript



Grant7
09-03-2007, 05:02 AM
Hi,

One of my clients has an html form that is validated server-side by the FormMail perl script.

They would like to add a "confirm email" field after the email field to try to eliminate users who enter their email address incorrectly.

I was wondering if this is possible to do using javascript to perhaps display an alert box should the users email address not match in both fields, and then send the email and verify using the perl script still after this javascript is validated on the client side?

Could anyone please let me know about this as soon as possible, and / or if you have an alternative solution please let me know?

Thanks very much.

Regards,

Grant

Philip M
09-03-2007, 07:51 AM
<form name = "myform">
<p> Enter Password (minimum 6 characters): - <input type = "password" name = "password" id = "password" size = "12"> </p>
<p> Confirm Password: - <input type = "password" name = "conpassword" id = "conpassword" size = "12" onblur = "checkPwd()"> </p>
</form>

<script type = "text/javascript">
function checkPwd() {
pwd = document.myform.password.value;
cpwd = document.myform.conpassword.value;
if ((pwd.length <6) || (pwd != cpwd)) {
alert ("Password too short or passwords do not match!")
document.myform.password.value = "";
document.myform.conpassword.value = "";
document.myform.password.focus();
}
else {
alert ("Passwords match!")
}
}

</script>

Grant7
09-03-2007, 08:03 AM
Thanks Philip, not exactly what I'm after but I might be able to figure something out from that.

I don't want the alert box to appear if the emails do match, I just want the form to be sent.

However if they don't, I want the alert box to popup and allow the user to change his/her entires.

Grant

Philip M
09-03-2007, 11:35 AM
Thanks Philip, not exactly what I'm after but I might be able to figure something out from that.

I don't want the alert box to appear if the emails do match, I just want the form to be sent.

However if they don't, I want the alert box to popup and allow the user to change his/her entires.

Grant


Well, as I see it that is what you have got. You could always delete the lines I put in simply for test purposes, so you could see that it works. :rolleyes:

else {
alert ("Passwords match!")
}


If the passwords do not match then the user gets the message:-

alert ("Password too short or passwords do not match!")

You can alter this to:-

alert ("Password too short or passwords do not match! Please re-enter them.")

Philip M
09-03-2007, 03:33 PM
I must apologise - for some stupid reason I mis-read your request as being for password validation and not the email validation/confirm that you actually wanted. :o :o :o

Try this:-

<form name = "myform">
<p> Enter E-Mail Address: - <input type = "text" name = "emailadd" id = "emailadd" size = "42" onblur = "checkValidEmail()"> </p>
<p> Confirm Email Address: - <input type = "text" name = "conemail" id = "conemail" size = "42" onblur = "checkConfirmEmail()"> </p>
</form>

<script type = "text/javascript">

function checkValidEmail() {
email1= document.myform.emailadd.value;
if (/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@(([\w\-]?)+\.)+([a-z]{2,4})$/i.test(email1)) {
alert ("Valid Address"); // simply comment out this line if not required
}
else {
alert ("Invalid Email Address - Please Re-Enter");
document.myform.emailadd.value = "";
document.myform.emailadd.focus();
}
}

function checkConfirmEmail() {
email2 = document.myform.conemail.value;
if (email2 != email1) {
alert ("Email addresses do not match - please re-enter!");
document.myform.emailadd.value = "";
document.myform.conemail.value = "";
document.myform.emailadd.focus();
}
else { // delete these lines if alert not required.
alert ("Passwords match!");
}
}

</script>

Once more, I am sorry for this misunderstanding. Too early on Monday morning! :eek:

Grant7
09-04-2007, 12:31 AM
Hehe no worries Philip, thanks that's great.

I actually had it working from what you wrote, but the last script you wrote is even better, checking the validity of the emails too, so that's awesome.

Thanks a lot for your help.

Regards,

Grant



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum