
function formValidator(){
	// Make quick references to our fields
	var name = document.getElementById('name');
	var email_id = document.getElementById('email_id');
	var comments = document.getElementById('comments');
	var code = document.getElementById('code');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(name, "Please enter your name")){
			if(emailValidator(email_id, "Please enter a valid email address")){
					if(notEmpty(comments, "Please enter your Comment")){
							if(isNumeric(code, "Please enter this Code")){
							return true;
						}
					}
				}
			}
	
	
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z\ \+]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+\ \[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}
	
	
	return false;
	
}


/*function formValidator(){
if ((document.comment.name.value=="")||
(document.comment.email_id.value=="")||
(document.comment.comments.value=="")||
(document.comment.code.value=="")){
.alert ("You must fill in all of the required .fields!")
.return false
.}
 else
 return true
}*/

