Link to home
Start Free TrialLog in
Avatar of robrodp
robrodpFlag for Mexico

asked on

Include a radio group in validation

I have this simple JS and works about 90% ok.

I need to include a part taht will validate a radio group to make sure an option has been selected.



<script language="JavaScript" type="text/JavaScript">


function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

function validateEmail(fieldValue) {
     return (/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/).test(fieldValue);
}


function Validate() {
              document.forma.nombre.value=trim(document.forma.nombre.value)
              if (document.forma.nombre.value.length == 0) {
               alert("Falta Nombre.")
                return(false)               }      

               document.forma.telefono.value=trim(document.forma.telefono.value)
               if (document.forma.telefono.value.length == 0) {
                alert("Falta Telefono.")
                return(false)                  }

        
              if (!validateEmail(document.forma.email.value)) {
           alert("La dirección de correo electrónico no es valida.");
           return false;
               }      




        return(true)
       


}



</script>
ASKER CERTIFIED SOLUTION
Avatar of 0h4crying0utloud
0h4crying0utloud

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial