Solved

Validation btn not working now?

Posted on 2003-12-02
36
815 Views
Last Modified: 2013-12-03
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>
0
Comment
Question by:needexpert
  • 9
  • 7
  • 7
  • +5
36 Comments
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
You have an extra quote:

ALT="Submit" "
0
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
Now let me try and find the js problem...
0
 
LVL 31

Assisted Solution

by:seanpowell
seanpowell earned 50 total points
Comment Utility
Case sensitivity issue?

<BODY ONLOAD=document.frmregistration.regname

should be:

<BODY ONLOAD=document.frmRegistration.regname
0
 

Author Comment

by:needexpert
Comment Utility
Let me try it.   I knew it was something so stupid... !!!! Thanks. Get right back to you.
0
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
Still not working - but not getting any errors...
0
 

Author Comment

by:needexpert
Comment Utility
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
 

Author Comment

by:needexpert
Comment Utility
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
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
Just doing the same thing...
0
 

Author Comment

by:needexpert
Comment Utility
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
 

Author Comment

by:needexpert
Comment Utility
How can I check to make sure > 1 between '@' and '.'?
0
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
Let me post a pointer to this Q from the Javascript section...
0
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
0
 
LVL 10

Assisted Solution

by:Bustarooms
Bustarooms earned 50 total points
Comment Utility
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
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
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
 
LVL 3

Assisted Solution

by:etain
etain earned 100 total points
Comment Utility
<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
 
LVL 3

Expert Comment

by:etain
Comment Utility
function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value)){
return (true)
}

0
 
LVL 35

Expert Comment

by:[ fanpages ]
Comment Utility
PS. A ".info" address would fail this validation!

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
Comment Utility
Suggest this instead:

function checkEmail(myForm)
{
  return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(myForm.emailAddr.value));
}
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 10

Expert Comment

by:Bustarooms
Comment Utility
not mine
0
 
LVL 16

Expert Comment

by:jaysolomon
Comment Utility
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
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
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
 
LVL 16

Expert Comment

by:jaysolomon
Comment Utility
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
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
>>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
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
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
 
LVL 16

Expert Comment

by:jaysolomon
Comment Utility
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
 
LVL 16

Expert Comment

by:jaysolomon
Comment Utility
NO POINTS TO ME
0
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
>>NO POINTS TO ME
??

why would you say that?


0
 
LVL 31

Expert Comment

by:seanpowell
Comment Utility
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
 
LVL 16

Expert Comment

by:jaysolomon
Comment Utility
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
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
let jay decide
0
 
LVL 16

Accepted Solution

by:
jaysolomon earned 150 total points
Comment Utility
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
 
LVL 16

Expert Comment

by:jaysolomon
Comment Utility
i added a submit button for testing purposes.

0
 
LVL 25

Assisted Solution

by:James Rodgers
James Rodgers earned 150 total points
Comment Utility
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
 

Author Comment

by:needexpert
Comment Utility
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
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
np... glad i was able to help
0
 
LVL 31

Expert Comment

by:GwynforWeb
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now