Click to See Complete Forum and Search --> : Validation help


cypressotter
11-22-2002, 01:28 PM
How do I combine the following two code snippits to ensure my customer's enter a "proper" email address?
What I have now on my site:
(Part one - returing customer login; part two - new customer login.)
<!--
function Login(Form) {
if (Form.txtEmail.value.length < 1) {
alert('You must enter your Email. ');
Form.txtEmail.focus();
return false;
}
if (Form.txtPassword.value.length < 1) {
alert('You must enter your password.');
Form.txtPassword.focus();
return false;
}
Form.login.value = 'Y';
Form.submit();
return true;
}

function Address(Form) {
if (Form.txtFirstName.value.length < 1) {
alert('You must enter your first name.');
Form.txtFirstName.focus();
return false;
}
if (Form.txtLastName.value.length < 1) {
alert('You must enter your last name.');
Form.txtLastName.focus();
return false;
}
if (Form.txtAddress1.value.length < 1 &&
Form.txtAddress2.value.length < 1) {
alert('You must enter your address.');
Form.txtAddress1.focus();
return false;
}
if (Form.txtCity.value.length < 1) {
alert('You must enter your City.');
Form.txtCity.focus();
return false;
}
if (Form.txtPhone.value.length < 1) {
alert('You must enter your Phone number.');
Form.txtPhone.focus();
return false;
}
if (Form.txtEmail.value.length < 1) {
alert('You must enter your Email address.');
Form.txtEmail.focus();
return false;
}
if (Form.txtPassword.value.length < 4) {
alert('You have entered an invalid
password.\nIt must be at least 4 characters and no more than 10.');
Form.txtPassword.focus();
return false;
}
else {
if (Form.txtPassword.value !=
Form.txtVerifyPassword.value) {
alert('Your password and verify
password fields do not match.');
Form.txtPassword.focus();
return false;
}
}
Form.payment.value = 'Y';
Form.submit();
}

//-->
</script>

And here's what I've found on the 'net for free that validates an email address to the form <yourname@domainname>:

<script language="JavaScript">
<!--

// -----------------------------------------------------------------
// Function : IsEmailValid
// Language : JavaScript
// Description : Checks if given email address is of valid syntax
// Copyright : (c) 1998 Shawn Dorman
// http://www.goodnet.com/~sdorman/web/IsEmailValid.html
// -----------------------------------------------------------------
// Ver Date Description of modification
// --- ---------- --------------------------------------------------
// 1.0 09/04/1996 Original write
// 1.1 09/30/1998 CHG: Use standard header format
// -----------------------------------------------------------------
// Source: Webmonkey Code Library
// (http://www.hotwired.com/webmonkey/javascript/code_library/)
// -----------------------------------------------------------------

function IsEmailValid(FormName,ElemName)
{
var EmailOk = true
var Temp = document.forms[login].elements[txtEmail]
var AtSym = Temp.value.indexOf('@')
var Period = Temp.value.lastIndexOf('.')
var Space = Temp.value.indexOf(' ')
var Length = Temp.value.length - 1 // Array is from 0 to length-1

if ((AtSym < 1) || // '@' cannot be in first
position
(Period <= AtSym+1) || // Must be atleast one valid
char btwn '@' and '.'
(Period == Length ) || // Must be atleast one valid
char after '.'
(Space != -1)) // No empty spaces permitted
{
EmailOk = false
alert('Please enter a valid e-mail address!')
Temp.focus()
}
return EmailOk
}


// -->

</script>

I'm simply not versed in js to know how to combine the functionality of the two!

Thanks for any help,
Topher Allan

cypressotter
11-22-2002, 09:16 PM
Bingo,
Thanks Dave!