Validation btn not working now?

I have read my code until I am blue in the face. I am doing a client side validation. I changed a couple of things but now I got something out of wake with my curly braces I think. Can someone please look at the code and tell me what I am doing wrong.  The check() function is where the problem is and the code was nicely formated until I pasted it here. Thanks for a fast reply.

<HTML>
<HEAD>
<TITLE>form</TITLE>


<SCRIPT language = "Javascript">



<!--

btnvalup = new Image; btnvalup.src = "images/BtnValidateGoldUp.jpg";
btnvaldown = new Image; btnvaldown.src = "images/BtnValidateGoldDown.jpg";

function MouseOver(BtnName)
{
      if (BtnName=="btnValidate")
      {
      document.btnValidate.src = btnvaldown.src;
      }
      
      if (BtnName=="btnSubmit")
      {
      document.btnSubmit.src = btnsubdown.src;
      }
}


function MouseOut(BtnName)
{
      if (BtnName=="btnValidate")
      {
      document.btnValidate.src = btnvalup.src;
      }
      
      if (BtnName=="btnSubmit")
      {
      document.btnSubmit.src = btnsubup.src;
      }
}


function check()
{
      var count=0;
      var msg="";

      for(i=0;i<=7;i++)
      {
               if(document.frmRegistration.elements[i].name=="regname")
            {
                   if(document.frmRegistration.elements[i].value.length<1)
                  {
                        count=1;
                        msg=msg+"\nName may not be left blank.";
                        document.frmRegistration.elements[i].focus();
                  }
                  
                  if(count==0)
                  {
                        if(document.frmRegistration.elements[i].value.length<6)
                        {
                              count=1;
                              msg=msg+"\nName must have a minimum of 6 characters.";
                              document.frmRegistration.elements[i].value="";
                              document.frmRegistration.elements[i].focus();
                        }
                  }
                  
                  if(document.frmRegistration.elements[i].value.length >25)
                  {
                        count=1;
                        msg=msg+"\nName cannot exceed 25 characters in length";
                        document.frmRegistration.elements[i].value="";
                        document.frmRegistration.elements[i].focus();
                  }
            }
            
            
            
            
            if(document.frmRegistration.elements[i].name=="email")
       {
                  emailchar=document.frmRegistration.email.value.split("@")

                  if(emailchar.length>1)
                  {
                        index=emailchar[1].indexOf(".")
                        if(index == -1)
                        {
                              document.frmRegistration.elements[i].focus()
                              return false
                        }
                        else
                        {
                              return true
                        }
                  }
                  else
                  {
                        document.frmRegistration.elements[i].focus()
                        return false
                  }
            }                  
 
            
            if(document.frmRegistration.elements[i].name=="login")
            {
                   if(document.frmRegistration.elements[i].value.length<1)
                  {
                        count=1;
                        msg=msg+"\nLogin Name may not be left blank.";
                        document.frmRegistration.elements[i].focus();
                  }
                  
                  if(count==0)
                  {
                        if(document.frmRegistration.elements[i].value.length<6)
                        {
                              count=1;
                              msg=msg+"\nLogin Name must have a minimum of 6 characters.";
                              document.frmRegistration.elements[i].value="";
                              document.frmRegistration.elements[i].focus();
                        }
                  }
                  
                  if(document.frmRegistration.elements[i].value.length >25)
                  {
                        count=1;
                        msg=msg+"\nLogin Name cannot exceed 25 characters in length";
                        document.frmRegistration.elements[i].value="";
                        document.frmRegistration.elements[i].focus();
                  }
            }      
            
            if(document.frmRegistration.elements[i].name=="password")
       {
                  if(document.frmRegistration.elements[i].value.length<1)
                  {
                        count=1;
                        msg=msg+"\nPassword may not be left blank.";
                        document.frmRegistration.elements[i].focus();
                  }
                  
                  if(count==0)
                  {
                        if(document.frmRegistration.elements[i].value.length<6)
                        {
                              count=1;
                              msg=msg+"\nPassword must have a minimum of 6 characters.";
                              document.frmRegistration.elements[i].value="";
                              document.frmRegistration.elements[i].focus();
                        }
                  }
                  
                  if(document.frmRegistration.elements[i].value.length >25)
                  {
                        count=1;
                        msg=msg+"\nPassword cannot exceed 25 characters in length";
                        document.frmRegistration.elements[i].value="";
                        document.frmRegistration.elements[i].focus();
                  }
            }
            
            else if((i>=7) && (count==0))
            {
                  return(true);
            }
      
      }
   
    for(i=0;i<=7;i++)
    {
        if(document.frmRegistration.elements[i].value=="")
        {
                  alert("PLEASE CORRECT THE FOLLOWING ERROR(S)\n "+msg);
                  document.frmRegistration.elements[i].focus();
                  return(false);
        }
    }
}
-->



</SCRIPT>
      
</HEAD>
 
<BODY ONLOAD=document.frmregistration.regname.focus() BGCOLOR = "#000066" TEXT = "#CC9900">

<CENTER>

<TABLE BORDER="1" CELLPADDING="0" WIDTH="55%">
      <TR>
            <TD>
                  <IMG SRC="images/HeadingRegistrationForm.jpg" NAME="heading" ALT="Registration Form" WIDTH="564" HEIGHT="63">

            </TD>
      </TR>
      
      <TR>
            <TD>
    <p align="center">
      <IMG SRC="images/LineGoldBlue.jpg" NAME="line" ALT="Gold Line" WIDTH="464" HEIGHT="6">

    </p>

            </TD>
      </TR>
</TABLE>
<center>
<FORM METHOD="post" ACTION="addDisplay.asp" NAME="frmRegistration">

<TABLE BORDER="1" CELLPADDING="3" WIDTH="427" height="279">
<center>
      <TR>
            <TD width="216" height="25"><font arial size="4">
               Name:
            </FONT></TD>

            <TD width="180" colspan="4" height="25">
                  <INPUT TYPE="text" NAME="regname" SIZE="35">
        </TD>

            <TD width="89" colspan="2" height="25">
        </TD>
      </TR>

    <tr>
            <TD width="216" height="25"><FONT Arial SIZE="4">
                  E-mail:
            </FONT></TD>
            
            <TD width="180" colspan="4" height="25">
                  <INPUT TYPE="text" NAME="email" SIZE="35">
            </TD>
            
            <TD width="89" colspan="2" height="25">
            </TD>
    </tr>
      <TR>
            <TD width="216" height="18"></TD>

            <TD width="269" colspan="6" height="18">
        </TD>
      </TR>

      <TR>
            <TD width="216" height="25"><font arial size="4">
                Login Name:
            </FONT></TD>

            <TD width="1" height="25">
                  <INPUT TYPE="text" NAME="login" SIZE="25">
        </TD>

            <TD width="0" colspan="2" height="25">
        </TD>

            <TD width="269" colspan="3" height="25">
        </TD>
      </TR>

      <TR>
            <TD width="216" height="41"><FONT Arial SIZE="4">
                  Password:
            </FONT></TD>

            <TD width="126" height="41">
                  <INPUT TYPE="password" NAME="password" SIZE="25">
            </TD>

 
            <TD width="111" rowspan="3" height="41" colspan="4">
            <p align="right" style="line-height: 100%"><font arial size="3"><b>
                              Remember&nbsp;&nbsp; password?</b></font>
                        <FONT Arial SIZE="4">
                    &nbsp;
                        </FONT>
            </TD>



            <TD width="32" rowspan="3" height="41">
            <INPUT TYPE="checkbox" NAME="checkbox" VALUE="yes" CHECKED>
            </TD>
      </TR>

    <tr>
            <TD width="216" height="18"></TD>

            <TD width="269" colspan="6" height="18"></TD>
    </tr>

    <tr>
            <TD width="216" height="23"><FONT Arial SIZE="4">
                  Title:
            </FONT></TD>

            <TD width="180" colspan="4" height="23"><FONT Arial SIZE="4">
                  <INPUT TYPE="radio" NAME="title" VALUE="Mr" CHECKED >Mr.  
                  <INPUT TYPE="radio" NAME="title" VALUE="Ms">Ms.  
                  <INPUT TYPE="radio" NAME="title" VALUE="Mrs">Mrs.  
            </FONT></TD>

            <TD width="89" colspan="2" height="23"></TD>
    </tr>

      <TR>
            <TD width="216" height="25"><FONT Arial SIZE="4">
                  Area of interest?
            </FONT></TD>
            
            <TD width="90" colspan="2" height="25">
             <SELECT SIZE="1" NAME="area">
                   <OPTION SELECTED VALUE="wd">Web Design</OPTION>
                   <OPTION VALUE="wp">Web Programming</OPTION>
                        <OPTION VALUE="wm">Web Marketing</OPTION>
                        <OPTION VALUE="wa">Web Administration</OPTION>
                  </SELECT>
            </TD>    
            
            <TD width="90" colspan="2" height="25">
            </TD>    
            
            <TD width="89" colspan="2" height="25">
            </TD>    
      </TR>

<!--      <TR HEIGHT="60" VALIGN="BOTTOM">-->
            
      
      
      
            <TD WIDTH="216" ALIGN="LEFT" height="18">
        <INPUT TYPE=image SRC="images/BtnValidateGoldUp.jpg" NAME="I10" ALT="Validate" ONCLICK="return check()" WIDTH="112" HEIGHT="23" onmouseover="MouseOver('btnvalidate')" onmouseout="MouseOut('btnvalidate')">
            </TD>
            
            <TD WIDTH="759" ALIGN="RIGHT" colspan="6" height="18">
        <INPUT TYPE=image SRC="images/BtnSubmitGoldUp.jpg" NAME="I11" ALT="Submit" " WIDTH="112" HEIGHT="23" onmouseover="MouseOver('btnsubmit')" onmouseout="MouseOut('btnsubmit')">
            </TD>
      
      
      </center>

</TABLE>

 
</FORM>
</center>

<font size = -1>All graphics used on this site were generated by using: <BR><a href="http://www.yahoo.com" style="color:
rgb(0,255,0)"><font color="FF00CC">http://www.flamingtext.com</font></a>
</BODY>
</HTML>
needexpertAsked:
Who is Participating?
 
jaysolomonConnect With a Mentor Commented:
not up to me, but here is my approach

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function isEmail(strValue){
      var objRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      return objRegExp.test(strValue);
}
function isEmpty(strFieldName){
     var strValue = strFieldName.value;
     strValue = strValue.split(" ").join("")
     if(strValue.length<1){
          return false;
          }
     return true;
}
function isChecked(strField){
      if (!strField.length)
            return strField.checked; // not a group
      for(var i = 0; i < strField.length; i++){
      if(strField[i].checked)
              return true; // yes one was ticked
  }
  return false;
}
function hasSelection(strField){
  return strField.selectedIndex > 0;
}
function validateForm(fObj){
      var strErr = "";
      if(!isEmpty(fObj.regname)){
            strErr += "- Your Name\n";
      }
      if(!isEmpty(fObj.email)){
            strErr += "- Email\n";
      }
      if(isEmpty(fObj.email)){
            if(!isEmail(fObj.email.value)){
                  strErr += "- Email is in the wrong format\n";
            }
      }
      if(!isEmpty(fObj.login)){
            strErr += "- Login\n";
      }
      if(!isEmpty(fObj.password)){
            strErr += "- Password\n";
      }
      if(!isChecked(fObj.title)){
            strErr += "- Title\n";
      }
      if(!hasSelection(fObj.area)){
            strErr += "- Area\n";
      }
      if(strErr != ""){
            alert("The following fields contain errors\n\n"+ strErr);
                  return false;
      }
   return true;
}

// -->
</script>
</head>
<body onload="document.forms[0].regname.focus()" BGCOLOR = "#000066" TEXT = "#CC9900">
<TABLE BORDER="1" CELLPADDING="0" WIDTH="55%">
     <TR>
          <TD>
               <IMG SRC="images/HeadingRegistrationForm.jpg" NAME="heading" ALT="Registration Form" WIDTH="564" HEIGHT="63">

          </TD>
     </TR>
     
     <TR>
          <TD>
    <p align="center">
     <IMG SRC="images/LineGoldBlue.jpg" NAME="line" ALT="Gold Line" WIDTH="464" HEIGHT="6">

    </p>

          </TD>
     </TR>
</TABLE>
<center>
<FORM METHOD="post" ACTION="addDisplay.asp" NAME="frmRegistration" onsubmit="return validateForm(this);">

<TABLE BORDER="1" CELLPADDING="3" WIDTH="427" height="279">
<center>
     <TR>
          <TD width="216" height="25"><font arial size="4">
             Name:
          </FONT></TD>

          <TD width="180" colspan="4" height="25">
               <INPUT TYPE="text" NAME="regname" SIZE="35">
        </TD>

          <TD width="89" colspan="2" height="25">
        </TD>
     </TR>

    <tr>
          <TD width="216" height="25"><FONT Arial SIZE="4">
               E-mail:
          </FONT></TD>
         
          <TD width="180" colspan="4" height="25">
               <INPUT TYPE="text" NAME="email" SIZE="35">
          </TD>
         
          <TD width="89" colspan="2" height="25">
          </TD>
    </tr>
     <TR>
          <TD width="216" height="18"></TD>

          <TD width="269" colspan="6" height="18">
        </TD>
     </TR>

     <TR>
          <TD width="216" height="25"><font arial size="4">
              Login Name:
          </FONT></TD>

          <TD width="1" height="25">
               <INPUT TYPE="text" NAME="login" SIZE="25">
        </TD>

          <TD width="0" colspan="2" height="25">
        </TD>

          <TD width="269" colspan="3" height="25">
        </TD>
     </TR>

     <TR>
          <TD width="216" height="41"><FONT Arial SIZE="4">
               Password:
          </FONT></TD>

          <TD width="126" height="41">
               <INPUT TYPE="password" NAME="password" SIZE="25">
          </TD>

 
          <TD width="111" rowspan="3" height="41" colspan="4">
            <p align="right" style="line-height: 100%"><font arial size="3"><b>
                         Remember&nbsp;&nbsp; password?</b></font>
                    <FONT Arial SIZE="4">
                    &nbsp;
                    </FONT>
          </TD>



          <TD width="32" rowspan="3" height="41">
            <INPUT TYPE="checkbox" NAME="checkbox" VALUE="yes" CHECKED>
          </TD>
     </TR>

    <tr>
          <TD width="216" height="18"></TD>

          <TD width="269" colspan="6" height="18"></TD>
    </tr>

    <tr>
          <TD width="216" height="23"><FONT Arial SIZE="4">
               Title:
          </FONT></TD>

          <TD width="180" colspan="4" height="23"><FONT Arial SIZE="4">
               <INPUT TYPE="radio" NAME="title" VALUE="Mr" CHECKED >Mr.  
               <INPUT TYPE="radio" NAME="title" VALUE="Ms">Ms.  
               <INPUT TYPE="radio" NAME="title" VALUE="Mrs">Mrs.  
          </FONT></TD>

          <TD width="89" colspan="2" height="23"></TD>
    </tr>

     <TR>
          <TD width="216" height="25"><FONT Arial SIZE="4">
               Area of interest?
          </FONT></TD>
          <TD width="90" colspan="2" height="25">
            <SELECT SIZE="1" NAME="area">
                        <option>Select One</option>
                 <OPTION VALUE="wd">Web Design</OPTION>
                 <OPTION VALUE="wp">Web Programming</OPTION>
                    <OPTION VALUE="wm">Web Marketing</OPTION>
                    <OPTION VALUE="wa">Web Administration</OPTION>
               </SELECT>
          </TD>    
          <TD width="90" colspan="2" height="25">
          </TD>    
          <TD width="89" colspan="2" height="25">
          </TD>    
     </TR>
<!--     <TR HEIGHT="60" VALIGN="BOTTOM">-->
          <TD WIDTH="216" ALIGN="LEFT" height="18">
        <INPUT TYPE=image SRC="images/BtnValidateGoldUp.jpg" NAME="I10" ALT="Validate" ONCLICK="return check()" WIDTH="112" HEIGHT="23" onmouseover="MouseOver('btnvalidate')" onmouseout="MouseOut('btnvalidate')">
          </TD>
          <TD WIDTH="759" ALIGN="RIGHT" colspan="6" height="18">
        <INPUT TYPE=image SRC="images/BtnSubmitGoldUp.jpg" NAME="I11" ALT="Submit" " WIDTH="112" HEIGHT="23" onmouseover="MouseOver('btnsubmit')" onmouseout="MouseOut('btnsubmit')">
          </TD>
     </center>
</TABLE>
<input type="submit" name="Submit" value="Submit">
</FORM>
</center>
<font size = -1>All graphics used on this site were generated by using: <BR><a href="http://www.yahoo.com" style="color:
rgb(0,255,0)"><font color="FF00CC">http://www.flamingtext.com</font></a>
</body>
</html>
0
 
seanpowellCommented:
You have an extra quote:

ALT="Submit" " 
0
 
seanpowellCommented:
Now let me try and find the js problem...
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
seanpowellConnect With a Mentor Commented:
Case sensitivity issue?

<BODY ONLOAD=document.frmregistration.regname

should be:

<BODY ONLOAD=document.frmRegistration.regname
0
 
needexpertAuthor Commented:
Let me try it.   I knew it was something so stupid... !!!! Thanks. Get right back to you.
0
 
seanpowellCommented:
Still not working - but not getting any errors...
0
 
needexpertAuthor Commented:
It seems to be the Validate button on the left that isn't working and I took the ONCLICK out of the Submit button and that is where the extra " came from but if I put it back in then it still doesn't validate using the check() function.
0
 
needexpertAuthor Commented:
I block out the email section which was the last thing I added and the validation works so it is in the email section of the check() function. I will keep looking.
0
 
seanpowellCommented:
Just doing the same thing...
0
 
needexpertAuthor Commented:
Seems that I got this code to work except for I can put a @ and . together so I guess I would use the split here



if(document.frmRegistration.elements[i].name=="email")
         {
                  if(document.frmRegistration.elements[i].value.length>1)
                  {
                        if(document.frmRegistration.elements[i].value.indexOf('.') < 0 ||
                           document.frmRegistration.elements[i].value.indexOf('@') > 
                           document.frmRegistration.elements[i].value.indexOf('.'))
                        {
                              count=1;
                              msg=msg+"\nE-mail address is invalid.";
                              document.frmRegistration.elements[i].value="";
                              document.frmRegistration.elements[i].focus();
                        }
                  }
                  
                  
                  
                  if(count==0)
                  {
                        if(document.frmRegistration.elements[i].value.length<7)
                        {
                              count=1;
                              msg=msg+"\nA valid E-mail address must have a minimum of 7 characters.";
                              document.frmRegistration.elements[i].value="";
                              document.frmRegistration.elements[i].focus();
                        }
                  }
                  
                  if(document.frmRegistration.elements[i].value.length >25)
                  {
                        count=1;
                        msg=msg+"\nE-mail address cannot exceed 25 characters in length";
                        document.frmRegistration.elements[i].value="";
                        document.frmRegistration.elements[i].focus();
                  }
            }
0
 
needexpertAuthor Commented:
How can I check to make sure > 1 between '@' and '.'?
0
 
seanpowellCommented:
Let me post a pointer to this Q from the Javascript section...
0
 
James RodgersWeb Applications DeveloperCommented:
0
 
BustaroomsConnect With a Mentor Commented:
i use a regex for email validation like so:

if(document.frmRegistration.elements[i].name=="email")
        {
               if(document.frmRegistration.elements[i].value.length >25)
               {
                    count=1;
                    msg=msg+"\nE-mail address cannot exceed 25 characters in length";
                    document.frmRegistration.elements[i].value="";
                    document.frmRegistration.elements[i].focus();
               }

               else if(document.frmRegistration.elements[i].value.length<7)
                    {
                         count=1;
                         msg=msg+"\nA valid E-mail address must have a minimum of 7 characters.";
                         document.frmRegistration.elements[i].value="";
                         document.frmRegistration.elements[i].focus();
                    }
               else
               {
           var x = document.frmRegistration.elements[i].value;
           var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
           if (!filter.test(x))
           {
                        msg=msg+"\nE-mail address is invalid.";
                         document.frmRegistration.elements[i].value="";
                         document.frmRegistration.elements[i].focus();
               }
               }                      

          }
0
 
James RodgersWeb Applications DeveloperCommented:
or
...


regEx= /^\w+([\.-]?\w+)*@\w+([\.-]?)\w*(\.\w{2,4})+$/


and in your validation routine

if(!regEx.test(textboxEmail.value)){
   alert("Invalid email format. Please enter a valid email.\n");
   return false;
}
0
 
etainConnect With a Mentor Commented:
<script language = "Javascript">

<!--

btnvalup = new Image; btnvalup.src = "images/BtnValidateGoldUp.jpg";
btnvaldown = new Image; btnvaldown.src = "images/BtnValidateGoldDown.jpg";

function MouseOver(BtnName)
{
     if (BtnName=="btnValidate")
     {
     document.btnValidate.src = btnvaldown.src;
     }
     
     if (BtnName=="btnSubmit")
     {
     document.btnSubmit.src = btnsubdown.src;
     }
}


function MouseOut(BtnName)
{
     if (BtnName=="btnValidate")
     {
     document.btnValidate.src = btnvalup.src;
     }
     
     if (BtnName=="btnSubmit")
     {
     document.btnSubmit.src = btnsubup.src;
     }
}


function check()
{
     var count=0;
     var msg="";

     for(i=0;i<=7;i++)
     {
       if(document.frmRegistration.elements[i].name=="regname")
          {

                         if(document.frmRegistration.elements[i].value == "")
               {
                    count=1;
                    msg=msg+"\nName may not be left blank.";
                    document.frmRegistration.elements[i].focus();
               }
               
               if(count==0)
               {
                    if(document.frmRegistration.elements[i].value.length<6)
                    {
                         count=1;
                         msg=msg+"\nName must have a minimum of 6 characters.";
                         document.frmRegistration.elements[i].value="";
                         document.frmRegistration.elements[i].focus();
                    }
               }
               
               if(document.frmRegistration.elements[i].value.length >25)
               {
                    count=1;
                    msg=msg+"\nName cannot exceed 25 characters in length";
                    document.frmRegistration.elements[i].value="";
                    document.frmRegistration.elements[i].focus();
               }
          }
         
         
         
         
        else  if(document.frmRegistration.elements[i].name=="email")
       {
               emailchar=document.frmRegistration.email.value.split("@")

               if(emailchar.length>1)
               {
                    index=emailchar[1].indexOf(".")
                    if(index == -1)
                    {
                         document.frmRegistration.elements[i].focus()
                                     document.frmRegistration.elements[i].value="";
                    msg=msg+"\nInvaild email.";
                    }
               }
               else
               {
                    document.frmRegistration.elements[i].focus()
                              document.frmRegistration.elements[i].value="";
                              msg=msg+"\nInvaild email.";
               }
          }              
 
         
         else if(document.frmRegistration.elements[i].name=="login")
          {
                 if(document.frmRegistration.elements[i].value.length<1)
               {
                    count=1;
                    msg=msg+"\nLogin Name may not be left blank.";
                    document.frmRegistration.elements[i].focus();
               }
               
               if(count==0)
               {
                    if(document.frmRegistration.elements[i].value.length<6)
                    {
                         count=1;
                         msg=msg+"\nLogin Name must have a minimum of 6 characters.";
                         document.frmRegistration.elements[i].value="";
                         document.frmRegistration.elements[i].focus();
                    }
               }
               
               if(document.frmRegistration.elements[i].value.length >25)
               {
                    count=1;
                    msg=msg+"\nLogin Name cannot exceed 25 characters in length";
                    document.frmRegistration.elements[i].value="";
                    document.frmRegistration.elements[i].focus();
               }
          }    
         
         else if(document.frmRegistration.elements[i].name=="password")
       {
               if(document.frmRegistration.elements[i].value.length<1)
               {
                    count=1;
                    msg=msg+"\nPassword may not be left blank.";
                    document.frmRegistration.elements[i].focus();
               }
               
               if(count==0)
               {
                    if(document.frmRegistration.elements[i].value.length<6)
                    {
                         count=1;
                         msg=msg+"\nPassword must have a minimum of 6 characters.";
                         document.frmRegistration.elements[i].value="";
                         document.frmRegistration.elements[i].focus();
                    }
               }
               
               if(document.frmRegistration.elements[i].value.length >25)
               {
                    count=1;
                    msg=msg+"\nPassword cannot exceed 25 characters in length";
                    document.frmRegistration.elements[i].value="";
                    document.frmRegistration.elements[i].focus();
               }
          }
         
          else if((i>=7) && (count==0))
          {
               return(true);
          }
     
     }
   
    for(i=0;i<=7;i++)
    {
        if(document.frmRegistration.elements[i].value=="")
        {
               alert("PLEASE CORRECT THE FOLLOWING ERROR(S)\n "+msg);
               document.frmRegistration.elements[i].focus();
               return(false);
        }
    }
}
-->

</script>
0
 
etainCommented:
function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value)){
return (true)
}

0
 
[ fanpages ]IT Services ConsultantCommented:
PS. A ".info" address would fail this validation!

BFN,

fp.
0
 
[ fanpages ]IT Services ConsultantCommented:
Suggest this instead:

function checkEmail(myForm)
{
  return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(myForm.emailAddr.value));
}
0
 
BustaroomsCommented:
not mine
0
 
jaysolomonCommented:
i would be glad to redo this whole form validation for you, but i need to know why you
are doing all of this looping?

I really do not see any need for a loop, unless all fields are required, but if they are
then we can make this code shorter, neater, easier to maintain.

Please let me know what exactly you wanna do
0
 
James RodgersWeb Applications DeveloperCommented:
already done Jay

      function check(){
    var count=0;
    var msg="";
      var strErr="";
      regExName=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExLog=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExPass=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExEmail= /^\w+([\.-]?\w+)*@\w+([\.-]?)\w*(\.\w{2,4})+$/;
      if(!regExName.test(document.getElementById('regname').value)){
            if(!strErr){
                  strErr='regname';
            }
            
            msg=msg+"\nInvalid format for Name.\n Name must be between 6 and 25 characters in length.";
      }      
      if(!regExEmail.test(document.getElementById('email').value)){
            if(!strErr){
                  strErr='email';
            }
            
            msg=msg+"\nInvalid format for Email.\n Please enter a valid email";
      }      
            
      if(!regExLog.test(document.getElementById('login').value)){
            if(!strErr){
                  strErr='login';
            }
            
            msg=msg+"\nInvalid format for Log In ID.\n Log In ID must be between 6 and 25 characters in length.";
      }      
      
      if(!regExPass.test(document.getElementById('password').value)){
            if(!strErr){
                  strErr='password';
            }
            msg=msg+"\nInvalid format for Password.\n Password must be between 6 and 25 characters in length.";
      }      
      
      if(msg){
            alert(msg);
            document.getElementById(strErr).focus();
      }      
      return (msg ? false : true);
}
-->
0
 
jaysolomonCommented:
Not really jester

yours will only work in browsers that support document.getElementById

you should use document.forms[0]

also to put focus to the first element, i would (since its a textbox) use document.forms[0].elements[0].focus();

also use <form name="form1" .......... onsubmit="return check();">


and do NOT use <input type="button"...onclick="check();">

use <input type="submit" name="btnSubmit" value="Submit">
0
 
James RodgersWeb Applications DeveloperCommented:
>>yours will only work in browsers that support document.getElementById
oops, thought this was ns 4+ but it is 6... my fault

>>also to put focus to the first element, i would (since its a textbox) use document.forms[0].elements[0].focus();
should be part of the onload, not the check function

>>also use <form name="form1" .......... onsubmit="return check();">
>><input type="submit" name="btnSubmit" value="Submit">
always do

>>and do NOT use <input type="button"...onclick="check();">
never

;-)
0
 
James RodgersWeb Applications DeveloperCommented:
ok here it is ns4+ and ie5+ compatible

      <script>
      function check(){
    var count=0;
    var msg="";
      var strErr="";
      regExName=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExLog=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExPass=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExEmail= /^\w+([\.-]?\w+)*@\w+([\.-]?)\w*(\.\w{2,4})+$/;
      if(!regExName.test(document.forms[0].elements['regname'].value)){
            if(!strErr){
                  strErr='regname';
            }
            
            msg=msg+"\nInvalid format for Name.\n Name must be between 6 and 25 characters in length.";
      }      
      if(!regExEmail.test(document.forms[0].elements['email'].value)){
            if(!strErr){
                  strErr='email';
            }
            
            msg=msg+"\nInvalid format for Email.\n Please enter a valid email";
      }      
            
      if(!regExLog.test(document.forms[0].elements['login'].value)){
            if(!strErr){
                  strErr='login';
            }
            
            msg=msg+"\nInvalid format for Log In ID.\n Log In ID must be between 6 and 25 characters in length.";
      }      
      
      if(!regExPass.test(document.forms[0].elements['password'].value)){
            if(!strErr){
                  strErr='password';
            }
            msg=msg+"\nInvalid format for Password.\n Password must be between 6 and 25 characters in length.";
      }      
      
      if(msg){
            alert(msg);
            document.forms[0].elements[strErr].focus();
      }      
      return (msg ? false : true);
}
-->
</script>
0
 
jaysolomonCommented:
my version of just email validation

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function isEmail(strValue){
      var objRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      return objRegExp.test(strValue);
}
function validateForm(fObj){
      var strErr = "";
      var focusField = "";
      if(!isEmail(fObj.email.value)){
            strErr += "Email is in the wrong format\n";
            if(focusField == "") focusField = "email";
      }
      if(strErr != ""){
            alert("The following fields contain errors\n\n"+ strErr);
                  eval("fObj."+ focusField +".focus()");
                        return false;
      }
   return true;
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="return validateForm(this);">
      <input type="text" name="email">
      <input type="submit" name="btnSubmit" value="Submit">
</form>
</body>
</html>
0
 
jaysolomonCommented:
NO POINTS TO ME
0
 
James RodgersWeb Applications DeveloperCommented:
>>NO POINTS TO ME
??

why would you say that?


0
 
seanpowellCommented:
The asker is going to have a hard time piecing all this together... any way we can agree on which is the best solution?
0
 
jaysolomonCommented:
No need in them, i was just posting another way to do it, so that if anyone else searches and
finds this once its paq they will have alternitives.

0
 
James RodgersWeb Applications DeveloperCommented:
let jay decide
0
 
jaysolomonCommented:
i added a submit button for testing purposes.

0
 
James RodgersConnect With a Mentor Web Applications DeveloperCommented:
and my version....  


<HTML>
<HEAD>
<TITLE>form</TITLE>


<SCRIPT language = "Javascript">



<!--

btnvalup = new Image; btnvalup.src = "images/BtnValidateGoldUp.jpg";
btnvaldown = new Image; btnvaldown.src = "images/BtnValidateGoldDown.jpg";

function MouseOver(BtnName)
{
     if (BtnName=="btnValidate")
     {
     document.btnValidate.src = btnvaldown.src;
     }
     
     if (BtnName=="btnSubmit")
     {
     document.btnSubmit.src = btnsubdown.src;
     }
}


function MouseOut(BtnName)
{
     if (BtnName=="btnValidate")
     {
     document.btnValidate.src = btnvalup.src;
     }
     
     if (BtnName=="btnSubmit")
     {
     document.btnSubmit.src = btnsubup.src;
     }
}


      function check(){
    var count=0;
    var msg="";
      var strErr="";
      regExName=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExLog=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExPass=/^[A-Z][A-Z '-]{4,23}[A-Z]$/gi;
      regExEmail= /^\w+([\.-]?\w+)*@\w+([\.-]?)\w*(\.\w{2,4})+$/;
      if(!regExName.test(document.forms[0].elements['regname'].value)){
            if(!strErr){
                  strErr='regname';
            }
            
            msg=msg+"\nInvalid format for Name.\n Name must be between 6 and 25 characters in length.";
      }      
      if(!regExEmail.test(document.forms[0].elements['email'].value)){
            if(!strErr){
                  strErr='email';
            }
            
            msg=msg+"\nInvalid format for Email.\n Please enter a valid email";
      }      
            
      if(!regExLog.test(document.forms[0].elements['login'].value)){
            if(!strErr){
                  strErr='login';
            }
            
            msg=msg+"\nInvalid format for Log In ID.\n Log In ID must be between 6 and 25 characters in length.";
      }      
      
      if(!regExPass.test(document.forms[0].elements['password'].value)){
            if(!strErr){
                  strErr='password';
            }
            msg=msg+"\nInvalid format for Password.\n Password must be between 6 and 25 characters in length.";
      }      
      if(!eval(document.forms[0].elements['title'].value)){
            if(!strErr){
                  strErr='title';
            }
            msg=msg+"\nPlease indicate your Title.";
      }
      if(!eval(document.forms[0].elements['area'].value)){
            if(!strErr){
                  strErr='title';
            }
            msg=msg+"\nPlease select an area of interest.";
      }
      
      if(msg){
            alert(msg);
            document.forms[0].elements[strErr].focus();
      }      
      return (msg ? false : true);
}
-->


</SCRIPT>
     
</HEAD>
 
<BODY ONLOAD="document.forms[0].elements[0].focus();" BGCOLOR = "#000066" TEXT = "#CC9900">

<CENTER>

<TABLE BORDER="1" CELLPADDING="0" WIDTH="55%">
     <TR>
          <TD>
               <IMG SRC="images/HeadingRegistrationForm.jpg" NAME="heading" ALT="Registration Form" WIDTH="564" HEIGHT="63">

          </TD>
     </TR>
     
     <TR>
          <TD>
    <p align="center">
     <IMG SRC="images/LineGoldBlue.jpg" NAME="line" ALT="Gold Line" WIDTH="464" HEIGHT="6">

    </p>

          </TD>
     </TR>
</TABLE>
<center>
<FORM METHOD="post" ACTION="addDisplay.asp" NAME="frmRegistration" onSubmit="return check()">

<TABLE BORDER="1" CELLPADDING="3" WIDTH="427" height="279">
<center>
     <TR>
          <TD width="216" height="25"><font arial size="4">
             Name:
          </FONT></TD>

          <TD width="180" colspan="4" height="25">
               <INPUT TYPE="text" NAME="regname" SIZE="35">
        </TD>

          <TD width="89" colspan="2" height="25">
        </TD>
     </TR>

    <tr>
          <TD width="216" height="25"><FONT Arial SIZE="4">
               E-mail:
          </FONT></TD>
         
          <TD width="180" colspan="4" height="25">
               <INPUT TYPE="text" NAME="email" SIZE="35">
          </TD>
         
          <TD width="89" colspan="2" height="25">
          </TD>
    </tr>
     <TR>
          <TD width="216" height="18"></TD>

          <TD width="269" colspan="6" height="18">
        </TD>
     </TR>

     <TR>
          <TD width="216" height="25"><font arial size="4">
              Login Name:
          </FONT></TD>

          <TD width="1" height="25">
               <INPUT TYPE="text" NAME="login" SIZE="25">
        </TD>

          <TD width="0" colspan="2" height="25">
        </TD>

          <TD width="269" colspan="3" height="25">
        </TD>
     </TR>

     <TR>
          <TD width="216" height="41"><FONT Arial SIZE="4">
               Password:
          </FONT></TD>

          <TD width="126" height="41">
               <INPUT TYPE="password" NAME="password" SIZE="25">
          </TD>

 
          <TD width="111" rowspan="3" height="41" colspan="4">
            <p align="right" style="line-height: 100%"><font arial size="3"><b>
                         Remember&nbsp;&nbsp; password?</b></font>
                    <FONT Arial SIZE="4">
                    &nbsp;
                    </FONT>
          </TD>



          <TD width="32" rowspan="3" height="41">
            <INPUT TYPE="checkbox" NAME="checkbox" VALUE="yes" CHECKED>
          </TD>
     </TR>

    <tr>
          <TD width="216" height="18"></TD>

          <TD width="269" colspan="6" height="18"></TD>
    </tr>

    <tr>
          <TD width="216" height="23"><FONT Arial SIZE="4">
               Title:
          </FONT></TD>

          <TD width="180" colspan="4" height="23"><FONT Arial SIZE="4">
                       <INPUT TYPE="radio" NAME="title" VALUE="0" style="display:none" checked>
               <INPUT TYPE="radio" NAME="title" VALUE="Mr" >Mr.  
               <INPUT TYPE="radio" NAME="title" VALUE="Ms">Ms.  
               <INPUT TYPE="radio" NAME="title" VALUE="Mrs">Mrs.  
          </FONT></TD>

          <TD width="89" colspan="2" height="23"></TD>
    </tr>

     <TR>
          <TD width="216" height="25"><FONT Arial SIZE="4">
               Area of interest?
          </FONT></TD>
         
          <TD width="90" colspan="2" height="25">
            <SELECT SIZE="1" NAME="area">
                         <OPTION SELECTED VALUE="0">--Select</OPTION>
                 <OPTION VALUE="wd">Web Design</OPTION>
                 <OPTION VALUE="wp">Web Programming</OPTION>
                 <OPTION VALUE="wm">Web Marketing</OPTION>
                 <OPTION VALUE="wa">Web Administration</OPTION>
               </SELECT>
          </TD>    
         
          <TD width="90" colspan="2" height="25">
          </TD>    
         
          <TD width="89" colspan="2" height="25">
          </TD>    
     </TR>

<!--     <TR HEIGHT="60" VALIGN="BOTTOM">-->
         
     
     
     
          <TD WIDTH="216" ALIGN="LEFT" height="18">
        <INPUT TYPE=image SRC="images/BtnValidateGoldUp.jpg" NAME="I10" ALT="Validate" ONCLICK="return check()" WIDTH="112" HEIGHT="23" onmouseover="MouseOver('btnvalidate')" onmouseout="MouseOut('btnvalidate')">
          </TD>
         
          <TD WIDTH="759" ALIGN="RIGHT" colspan="6" height="18">
        <INPUT TYPE=image SRC="images/BtnSubmitGoldUp.jpg" NAME="I11" ALT="Submit" " WIDTH="112" HEIGHT="23" onmouseover="MouseOver('btnsubmit')" onmouseout="MouseOut('btnsubmit')">
          </TD>
     
     
     </center>

</TABLE>

 
</FORM>
</center>

<font size = -1>All graphics used on this site were generated by using: <BR><a href="http://www.yahoo.com" style="color:
rgb(0,255,0)"><font color="FF00CC">http://www.flamingtext.com</font></a>
</BODY>
</HTML>
0
 
needexpertAuthor Commented:
I managed to get it done without reading these posted comments, however l appreciate everyones comments and help. I will review and decide where to distribute the points and I know that I will learn from your postings.
Thanks again.
0
 
James RodgersWeb Applications DeveloperCommented:
np... glad i was able to help
0
 
GwynforWebCommented:
There is no known email regex that is perfect, there are dozens and dozens of valid email forms this is one ot he better regex's

/(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.