    function checkdate(f){
//	window.onerror=null // for all other strange errors
	var err=0
	var psj=0;
	a=f.value
	if (a.length != 10) err=1
	b = a.substring(0, 2)// month
	c = a.substring(2, 3)// '/'
	d = a.substring(3, 5)// day
	e = a.substring(5, 6)// '/'
	f = a.substring(6, 10)// year

	//basic error checking
	if (b<1 || b>12) err = 1
	if (c != '/') err = 1
	if (d<1 || d>31) err = 1
	if (e != '/') err = 1
	if (f<0 || f>3000) err = 1
	
	//advanced error checking

	// months with 30 days
	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) err=1
	}

	// february, leap year
	if (b==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}

		if (d>29) err=1
		if (d==29 && ((f/4)!=parseInt(f/4))) err=1
	}

	if (err==1){
		return false;
	}
	else{
		return true;
	}

}

    function checkdateDD(f){
//	window.onerror=null // for all other strange errors
	var err=0
	var psj=0;
	a=f.value
	if (a.length != 10) err=1
	b = a.substring(0, 2)// day
	c = a.substring(2, 3)// '/'
	d = a.substring(3, 5)// month
	e = a.substring(5, 6)// '/'
	f = a.substring(6, 10)// year

	//basic error checking
	if (b<1 || b>31) err = 1
	if (c != '/') err = 1
	if (d<1 || d>12) err = 1
	if (e != '/') err = 1
	if (f<0 || f>3000) err = 1
	
	//advanced error checking

	// months with 30 days
	if (d==4 || d==6 || d==9 || d==11){
		if (b==31) err=1
	}

	// february, leap year
	if (d==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}

		if (b>29) err=1
		if (b==29 && ((f/4)!=parseInt(f/4))) err=1
	}

	if (err==1){
		return false;
	}
	else{
		return true;
	}

}
//verifica si la longitud de un string es de 10 exactamente
function maximo10(s)
{ x = s.value;
	if ((x.length<10) || (x.length>10))
	{
		return false;}
	else
		return true;
}

function lengthLada(s)
{ x = s.value;
	if ((x.length >= 2) && (x.length <= 3))
	{
		return true;}
	else
		return false;
}

    //A utility function that returns true if a string contains only a whitespace
	//characters
	function isblank(s)
	{	if (s.length==0)//added to return true if the field doesn't have information
		{return true;}
		for(var i=0;i<s.length;i++)
		{
			var c = s.charAt(i);
			if((c!=' ') && (c!='\n') && (c!='\t'))
		        return false;
        }
        return true;	
	}	

	function verify(f)
	{
		var msg;
		var empty_fields = "";
		var errors=""; 	
        var lastradio = "";
		var firstElement = null;
		var bandera = false;
		
		for(var i=0;i<f.length;i++)
		{
			var e=f.elements[i];
            
			if(((e.type=="text")||(e.type=="textarea")||(e.type=="file")) && !e.optional)
			{
				//first check if the field is empty
				if((e.value==null) || (e.value=="") || isblank(e.value))
				{
                    if(e.description!=null && e.description!="")
                    {
                        empty_fields+="\n        " + e.description;
                    }
                    else
                    {
                        empty_fields+="\n        " + e.name;
                    }
					if(firstElement == null)
						firstElement = e;
					continue;
				}
                else
                {
                    //check for email 
                    if(e.email != null && e.email != "")
                    {
                        var res = emailCheck(e.value);
                        if(res != "")
                        {
                            if(e.description!=null && e.description!="")
                            {
                                errors+="- " + res + "\n";
                                errors+="        " + e.description + "\n";
                            }
                            else
                            {
                                errors+="- " + res + "\n";
                                errors+="        " + e.name + "\n";
                            }
							if(firstElement == null)
								firstElement = e;
        					continue;
                        }
                    }
                }
			}
            
					//check for a date
					if((e.date != null) && (e.date != "")&&(e.value !=""))
					{
						
						if(!checkdate(e))
                            {
                                //errors+="- " + "The field " + "\n";
                                errors+="        " + e.description + " es Fecha Inválida (MM/DD/AAAA)\n";
                                if(firstElement == null)
        						    firstElement = e;
                                continue;    
                                
                            }
                        
					}		
					
					//check for a date
					if((e.datedd != null) && (e.datedd != "")&&(e.value !=""))
					{
						
						if(!checkdateDD(e))
                            {
                                //errors+="- " + "The field " + "\n";
                                errors+="        " + e.description + " es Fecha Inválida (DD/MM/AAAA)\n";
                                if(firstElement == null)
        						    firstElement = e;
                                continue;    
                                
                            }
                        
					}		
			//checks si la longitud de telefono es de 10 digitos si este pertenece a mexico
			if ((e.telefono != null) && (e.telefono != "") && (e.value != "")) 
			{
				if(!maximo10(e))
				{
				//error
					bandera = true;
					errors+= e.description + " debe contener exactamente 10 dígitos entre los dos\n";
					if(firstElement == null)
						fistElement = e;
					continue;
				}
			}
			//verifica si la longintud de la lada es 2 o 3 si es de mexico
			if ((e.lada != null) && (e.lada != "") && (e.value != "")) 
			{
				if(!lengthLada(e))
				{
				//error
					bandera = true;
					errors+= e.description + " debe contener entre 2 y 3 dígitos\n";
					if(firstElement == null)
						fistElement = e;
					continue;
				}
			}

            //checks for a radio 
            if(e.type=="radio" && !e.optional)
            {                    
                if(lastradio == "" || lastradio != e.name)
                {
                    lastradio = e.name;
                }
                else
                {
                    continue;
                }
                if(lastradio == e.name)
                {
                    if (!isChecked(f, e))
                    {
                        if(e.description!=null && e.description!="")
                        {
                            empty_fields+="\n        " + e.description;
                        }
                        else
                        {
                            empty_fields+="\n        " + e.name;
                        }
						if(firstElement == null)
							firstElement = e;
                    }
                }
                continue;
            }
			
            if(e.type=="password")
            {
                if((e.value==null) || (e.value=="") || isblank(e.value))
				{
                    if(e.description!=null && e.description!="")
                    {
                        empty_fields+="\n        " + e.description;
                    }
                    else
                    {
                        empty_fields+="\n        " + e.name;
                    }
					if(firstElement == null)
						firstElement = e;
					continue;
				}
                
                if(e.confirm != null && e.confirm != "")
                {   
                    
                    if(e.value != f.elements[e.confirm].value)
                    {                                                                             
                       errors+="- La confirmación de password es incorrecta.\n";
                    }
					if(firstElement == null)
						firstElement = e;
                    continue;
                }
            }
            
            //check for select
            if((e.type=="select-one" || e.type=="select-multiple") && !e.optional)
            {
                
                if(e.selectedIndex == -1)
                {
                    if(e.description!=null && e.description!="")
                    {
                        empty_fields+="\n        " + e.description;
                    }
                    else
                    {
                        empty_fields+="\n        " + e.name;
                    }
					if(firstElement == null)
						firstElement = e;
					continue;
                }
                else
                {
                    if(e.options[e.selectedIndex].value=="")
                    {
                        if(e.description!=null && e.description!="")
                        {
                            empty_fields+="\n        " + e.description;
                        }
                        else
                        {
                            empty_fields+="\n        " + e.name;
                        }
						if(firstElement == null)
							firstElement = e;
    					continue;
    				}
                }
            }
            
            
			//now check for fields that are supposed to be numeric
			if ((e.numeric || (e.min!=null) || (e.max!=null)) && (!isblank(e.value)))
			{
				var v = parseFloat(e.value);
				if(isNaN(v) || ((e.min!=null)&&(v<e.min)) || ((e.max!=null)&&(v>e.max)))
				{
                    if(e.description!=null && e.description!="")
                    {
                        errors+="- El campo " + e.description + " debe ser númerico";
                    }
                    else
                    {
                        errors+="- El campo " + e.name + " debe ser numerico";
                    }
					if(e.min!=null)
						errors+=" mayor que " + e.min;
					if(e.min!=null && e.max!=null)
						errors+=" menor que " + e.max;
					else if(e.max!=null)
						errors+=" menor que " + e.max;
					errors+=".\n";
					if(firstElement == null)
						firstElement = e;
				}
				else
				{
					if(e.value!=v)
					{
						if(e.description!=null && e.description!="")
	                    {
							errors+="- El campo " + e.description + " debe ser numerico";
						}
						else
                    	{
                        	errors+="- El campo " + e.name + " debe ser numerico";
	                    }
						errors+=".\n";
						if(firstElement == null)
							firstElement = e;
					}
					
				}
			}
		}	


		//Now, if there were any errors, display the messages, and return false to prevent
		//the form from being submitted. Otherwise return true.

		if(!empty_fields && !errors)
			return true;
		
		msg =  "-------------------------------------------------------------\n\n";
		msg += "La forma no fue enviada por los siguientes errores.\n";
		msg += "Por favor corrija estos errores y vuelva a enviar.\n";
		msg += "-------------------------------------------------------------\n\n";

		if (empty_fields)
		{
			msg += " - Los siguientes campos requeridos estan vacíos:" + empty_fields + "\n";
			if(errors) msg += "\n";
		}

		msg += errors;
		alert(msg);	
		if (bandera) 
			return false;
		else
		{
			firstElement.focus();
			return false;
		}
	}
    
    //verify if a radio is checked
    function isChecked(f, radio)
    {
        for(var i=0;i<f.length;i++)
        {
            var e=f.elements[i];
            if (e.name == radio.name)
            {
                if (e.checked)
                {
                    return true;
                }
            }
        }
        return false;
    }
    
    
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function emailCheck (emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	return "La dirección de correo electronico es incorrecta (verifica @ y .'s)";
	//return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    return "La cuenta de correo es incorrecta";
    //return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        return "La dirección de correo electronico es incorrecta!";
		//return false
	    }
    }
    return "";
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	return "La dirección de correo electronico es incorrecta!";
    //return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   return "La dirección de correo electronico es incorrecta!";
   //return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="La dirección de correo electronico es incorrecta!"
   return errStr;
   //return false
}

// If we've gotten this far, everything's valid!
return "";
}
//  End -->
