Solved

Include a radio group in validation

Posted on 2006-06-12
1
211 Views
Last Modified: 2013-11-18
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>
0
Comment
Question by:robrodp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
0h4crying0utloud earned 500 total points
ID: 16889117
somn like this should work:

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;
              }    


         var myOption = -1;
         for (i=document.forma.radioGroupName.length-1; i > -1; i--) {
           if (document.forma.radioGroupName[i].checked) {
             myOption = i;
           }
         }
         if (myOption == -1) {
            alert("You must select a radio button");
            return (false);
         }

        return(true)
       


}
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question