Código HTML:
 function validar(f) { 
	var errorMsg = "";
	if (document.f.nombre.value.length == 0) { 
		errorMsg += "\n\tNombre \t- Debe cargar el Nombre, es un dato obligatorio";
	}	
	if (document.f.apellido.value.length == 0) { 
		errorMsg += "\n\tApellido \t- Debe cargar el Apellido, es un dato obligatorio";
	}	
	if (document.f.email.value.length == 0) { 
		errorMsg += "\n\tE-mail \t- Debe cargar el Email, es un dato obligatorio";
	}	
	if (document.f.email2.value.length == 0) { 
		errorMsg += "\n\tConfirmación de E-mail \t- Debe cargar la confirmación del Email, es un dato obligatorio";
	}
	
	if(f.email.value!='' && f.email2.value!=''){
  		if (f.email.value != f.email2.value) { 
			errorMsg += "\n\tConfirmación de E-mail \t- Los campos de email tienen que ser iguales";
  } 
  }
  if (errorMsg != ""){
		msg = "______________________________________________________________\n\n";
		msg += "ERROR!.\n";
		msg += "Por Favor revise los datos ingresados.\n";
		msg += "______________________________________________________________\n\n";
		
		errorMsg += alert(msg + errorMsg + "\n\n");
		return false;
	}
		return true;
}
Código HTML:
 <form action="form_contactenos.php" method="post" name="Contacto" id="Contacto" onSubmit="return validar(this)">  
 


