Hi there,

I'm working on someone else's site, and I need to add something to their form to make sure that the email address people enter is the correct format (i.e. it has a @ sign and a "."). It currently only checks if there is anything in the field at all.

This is the javascript validation that they're currently using:

<script language = "javascript">

function verifyEnEnquiry(theform) {
	var my_message = "default";
	if(document.enquiries.FullName.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Full Name').'");
		//return false;	
	} else
	if(document.enquiries.Company.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Company Name').'");
		//return false;	
	} else	
	if(document.enquiries.Email.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Email ').'");
		//return false;	
	} else	
	if(document.enquiries.address_4.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your City').'");
		//return false;	
	} else	
	if(document.enquiries.Enquiry.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Enquiry ').'");
		//return false;	
	} else	
	if(document.enquiries.JobTitle.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Job Title').'");
		//return false;	
	} else
	if(document.enquiries.country.selectedIndex == 0)
	{
		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Country').'");
		//return false;
	} else	
	if(document.enquiries.address_1.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Address').'");
		//return false;	
	} else
	if(document.enquiries.Postcode.value == "") {

		alert("'.$sb->dt('Sorry, but you cannot proceed unless you complete your Postcode').'");
		//return false;	
	}
	else {

		//return true;
		document.enquiries.submit();
	}
	//alert(my_message);
}

</script>

What do I need to add to that to get it to check the @ and "." too?

Any help with this would be great. Working to a deadline and to be honest, I'm not really a web designer (just have a vague understanding of stuff).

Hi,

If you google, You can get numerous articles about email validation in javascript.

here is the one;

function validateEmailAddress(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\
".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA
-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

Thank you,

Any help with this would be great. Working to a deadline and to be honest, I'm not really a web designer (just have a vague understanding of stuff).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.