I am having trouble validating with the email field in the form. I believe the problem is in the function validateEmail. I need the email field in the form to check anything less than a full email address, in the format of [email][email protected]
[CODE]
function validateEmail(fld) {
// var error=””;
// var email = document.demo.email.value;
//email = email.replace(/^s+|s+$/, ”);
var tfld = trim(fld.value); // value of field with whitespace trimmed off
// var emailFilter = /^[^@]+@[^@.]+.[^@]*ww$/ ;
var emailPattern = /^[_a-zA-Z0-9\-]+(.[_a-zA-Z0-9\-]+)*@[a-zA-Z0-9\-]+(.[a-zA-Z0-9\-]+)*(.[a-z]{2,3})$/;
var illegalChars= /[()<>,;:\”[]]/ ;
var email = “[email protected]”;
/*
if (emailPattern.test(tfld)) {
window.alert(“You entered a valid e-mail address.”);
}
else {
window.alert(“You didn’t enter a valid e-mail address”);
fld.style.background = ‘Yellow’; }
/* else {
fld.style.background = ‘White’;
}
*/
if (fld.value == “”) {
fld.style.background = ‘Yellow’;
error = “You didn’t enter an email address.n”;
} else if (emailPattern.test(tfld)) {
fld.style.background = ‘Yellow’;
error = “Name has to be in [email protected]”;
} else if (fld.value.match(illegalChars)) { //test email for illegal characters
fld.style.background = ‘Yellow’;
error = “The email address contains illegal characters.n”;
} else if (!(/^([a-z0-9])([w.-+])+([a-z0-9])@((w)([w-]?)+.)+(com|net|org)$/i.test(email))) {
fld.style.background = ‘Yellow’;
error = “Invalid address, top level domain (has to be .com .net or .org).n”;
} else {
fld.style.background = ‘White’;
}
return error;
}
my whole code:
[url]http://ceweb.uml.edu/jberg14527/Javascript/formvalidationValidate.html
can’t find the attached file feature, copy and paste from page source to see how it works.