Solved

Validation btn not working now?

Posted on 2003-12-02
36
819 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
ID: 9863469
You have an extra quote:

ALT="Submit" " 
0
 
LVL 31

Expert Comment

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

Assisted Solution

by:seanpowell
seanpowell earned 50 total points
ID: 9863487
Case sensitivity issue?

<BODY ONLOAD=document.frmregistration.regname

should be:

<BODY ONLOAD=document.frmRegistration.regname
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

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

Expert Comment

by:seanpowell
ID: 9863547
Still not working - but not getting any errors...
0
 

Author Comment

by:needexpert
ID: 9863565
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
ID: 9863590
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
ID: 9863617
Just doing the same thing...
0
 

Author Comment

by:needexpert
ID: 9863864
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
ID: 9863913
How can I check to make sure > 1 between '@' and '.'?
0
 
LVL 31

Expert Comment

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

Expert Comment

by:James Rodgers
ID: 9866321
0
 
LVL 10

Assisted Solution

by:Bustarooms
Bustarooms earned 50 total points
ID: 9866322
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
ID: 9866350
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
ID: 9866380
<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
ID: 9866396
function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.emailAddr.value)){
return (true)
}

0
 
LVL 35

Expert Comment

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

BFN,

fp.
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 9866553
Suggest this instead:

function checkEmail(myForm)
{
  return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(myForm.emailAddr.value));
}
0
 
LVL 10

Expert Comment

by:Bustarooms
ID: 9866555
not mine
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9866654
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
ID: 9866716
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
ID: 9866757
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
ID: 9866827
>>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
ID: 9867115
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
ID: 9867201
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
ID: 9867208
NO POINTS TO ME
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 9867252
>>NO POINTS TO ME
??

why would you say that?


0
 
LVL 31

Expert Comment

by:seanpowell
ID: 9867299
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
ID: 9867302
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
ID: 9867420
let jay decide
0
 
LVL 16

Accepted Solution

by:
jaysolomon earned 150 total points
ID: 9867546
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
ID: 9867549
i added a submit button for testing purposes.

0
 
LVL 25

Assisted Solution

by:James Rodgers
James Rodgers earned 150 total points
ID: 9867665
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
ID: 9872489
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
ID: 9874158
np... glad i was able to help
0
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 9886397
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

772 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