954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Email form validation

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?

hindu times
Junior Poster
125 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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).

hindu times
Junior Poster
125 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

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).

MeSampath
Junior Poster
102 posts since Oct 2009
Reputation Points: 23
Solved Threads: 27
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: