Help verifying two email fields in a form.
|
| View previous topic :: View next topic |
| Author |
Message |
vanbot
Joined: 11 Jun 2008 Posts: 1
|
Posted: Wed Jun 11, 2008 5:32 am Post subject: Help verifying two email fields in a form. |
|
|
Hi there, I am trying to validate that two emails in the form match. The function checkemailmatch doesn't seem to be working, does anyone see what I could be doing wrong? Thank you!
~Vanessa
<SCRIPT LANGUAGE="JavaScript">
<!--
var error = new createerror();
var errors = new Array();
errors[31] = "Illegal character in a numeric input";
errors[64] = "The field is empty.";
errors[131] = "Illegal character. You can only enter letters and blank spaces.";
errors[150] = "Please input a valid email address.";
errors[151] = "Please input a valid ten digit number.";
errors[152] = "The email addresses are not the same.";
var alphachars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var emailFilter=/^.+@.+\..{2,3,4,6}$/;
var digits = "0123456789";
function createerror() {
this.val = 0;
return this;
}
function validateForm() {
var correct;
correct = checkblank(document.myForm.name.value, error);
if (!correct) {
alert('Name: ' + errors[error.val]);
document.myForm.name.focus();
return false;
}
correct = checkalpha(document.myForm.name.value, error);
if (!correct){
alert('Name: ' + errors[error.val]);
document.myForm.name.focus();
return false;
}
correct = checkblank(document.myForm.lastname.value, error);
if (!correct) {
alert('Last Name: ' + errors[error.val]);
document.myForm.lastname.focus();
return false;
}
correct = checkalpha(document.myForm.lastname.value, error);
if (!correct){
alert('Last Name: ' + errors[error.val]);
document.myForm.lastname.focus();
return false;
}
correct = checkblank(document.myForm.email.value, error);
if (!correct) {
alert('Email: ' + errors[error.val]);
document.myForm.email.focus();
return false;
}
correct = checkemail(document.myForm.email.value, error);
if (!correct) {
alert('Email: ' + errors[error.val]);
document.myForm.email.focus();
return false;
}
correct = checkblank(document.myForm.confirmemail.value, error);
if (!correct) {
alert('Confirm Email: ' + errors[error.val]);
document.myForm.confirmemail.focus();
return false;
}
correct = checkemail(document.myForm.confirmemail.value, error);
if (!correct) {
alert('Confirm Email: ' + errors[error.val]);
document.myForm.confirmemail.focus();
return false;
}
correct = checkblank(document.myForm.phone.value, error);
if (!correct) {
alert('Phone: ' + errors[error.val]);
document.myForm.phone.focus();
return false;
}
correct = checkphonenumber(document.myForm.phone.value, error);
if (!correct) {
alert('Phone: ' + errors[error.val]);
document.myForm.phone.focus();
return false;
}
correct = checkblank(document.myForm.fax.value, error);
if (!correct) {
alert('Fax: ' + errors[error.val]);
document.myForm.fax.focus();
return false;
}
correct = checkphonenumber(document.myForm.fax.value, error);
if (!correct) {
alert('Fax: ' + errors[error.val]);
document.myForm.fax.focus();
return false;
}
return true;
}
function checkblank(fieldValue,error)
{
if (fieldValue.length == 0) {
error.val = 64;
return false;
}
for (var i = 0; i<fieldValue.length; i++) {
if (fieldValue.charAt(i) != ' ' && fieldValue.charAt(i) != '\t') {
return true;
}
}
error.val = 64;
return false;
}
function isalpha(sChar){return (alphachars.indexOf(sChar) >= 0)}
function checkalpha(fieldValue,error)
{
for (var i = 0; i<fieldValue.length;i++)
{
if (!isalpha(fieldValue.charAt(i))){
error.val = 131;
return false;
}
}
return true;
}
function checkemail(){
var str=document.myForm.email.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
error.val = 150;
return false;
}
return true;
}
function checkconfirmemail(){
var str=document.myForm.confirmemail.value
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str))
testresults=true
else{
error.val = 150;
return false;
}
return true;
}
function checkemailmatch(error){
var str=document.myForm.email.value
var str2=document.myForm.confirmemail.value
}
correct = checkemailmatch(error);
{
if (str==str2)
testresults=true
else{
error.val = 152;
return false;
}
return true;
}
function checkphonenumber(str){
var re = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
if (re.test(str))
testresults=true
else{
error.val = 151;
return false;
}
return true;
}
// -->
</SCRIPT>
</HEAD>
<BODY bgcolor="#000000"><font color="#ffffff">
<center>
<H2>Contact Us</H2>
<h4>*Indicates a required field</h4>
<FORM NAME="myForm" METHOD="post"
ACTION="http://free.allforms.mailjol.net/u/d0ac0bdf.php">
*Name:<BR>
<INPUT TYPE="text" size="30" NAME="name" ><br>
*Last Name:<BR>
<input type="text" size="30" name="lastname"><br/>
Street Address:<br />
<input name="Street" type="text" size="30" />
<br/>
Unit#:<br/> <input name="Unit" type="text" size="5" />
<br />
City:<br /> <input name="City" type="text" size="30" />
<br/>
Postal Code: <br /><input name="PostalCode" type="text" size="7"/>
<br/>
*Email address:<BR>
<INPUT TYPE="text" size="30" NAME="email"><br>
*Confirm Email address:<BR>
<INPUT TYPE="text" size="30" NAME="confirmemail"><br>
*Phone number:<BR>
<INPUT TYPE="text" size="30" NAME="phone"><br>
Mobile number:<BR>
<INPUT TYPE="text" size="30" NAME="mobile"><br />
Work Phone:<br/>
<input name="Work" type="text" size="20" maxlength="12" /><br />
Comments: <br/>
<textarea name="Comments" rows="10" cols="50">Let us know what you think!</textarea>
<br />
<INPUT TYPE="submit" VALUE="Submit Data" onClick="javascript:return validateForm();">
<INPUT TYPE="reset" VALUE="Reset Form">
</FORM>
</font>
</BODY>
</HTML> |
|
| Back to top |
|
 |
|
|
Johnathan 500+ Club

Joined: 31 May 2007 Posts: 996 Location: Belfast, Northen Ireland
|
|
| Back to top |
|
 |
|
Welcome to DEVPPL.com
You are not logged in, which means that you can't post in the forums. Click here to Register
If you are a current member here on DEVPPL, please login below:
|
|
|
|