Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NEED URGENT HELP WITH VALIDATION! 1

Status
Not open for further replies.

dsk525

Programmer
Mar 13, 2002
73
US
Hi all,

I need to do validation on a passwordrequest form.

I just need to validate user data at the client side for that particular page.

Any help with code or suggestions would be of much help!!!

Thank you in advance!

 
what do you want to validate? the password? I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
You just need a simple piece of JavaScript depending on what you want to validate, if you wanted someone to enter number chars only for example :

Code:
<script
  language=&quot;JavaScript&quot;
  type=&quot;text/JavaScript&quot;
>
<!--
    function formVal (form, elmt) {
        var valid = &quot; 0123456789&quot;;
        var rtn = true;
        var temp;
        for (var i = 0; i < form[elmt].value.length; i++) {
            temp = form[elmt].value.toLowerCase().substring (i, i+1);
            if (valid.indexOf (temp) == -1) {
                rtn = false;
            }
        }
        if (rtn == false) {
            alert (&quot;Please enter numbers only&quot;);
            form[elmt].focus ();
        }
        return rtn;
    }
//-->
</script>

<form
  action=&quot;page.asp&quot;
  onsubmit=&quot;return formVal (this, 'username');&quot;
>
  Username: <input
    type=&quot;text&quot;
    name=&quot;username&quot;
  ><br />
  Password: <input
    type=&quot;password&quot;
    name=&quot;password&quot;
  ><br />
  <input
    type=&quot;submit&quot;
    value=&quot;Log In&quot;
  >
</form>

If you want more advice explain what you want to validate Regards

David Byng

spider.gif


davidbyng@hotmail.com
 
Hi,

I need to validate, FaxNumber, and PhoneNumber fields to see if it contains number. I need to validate and FORCE (mandatory) the user to fill out CompanyName, email, LastName and FirstName field.

My existing code is written below,

Thank you very much!


<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<DIV ALIGN=&quot;LEFT&quot;><FONT FACE=&quot;Verdana, Arial, Helvetica, sans-serif&quot; SIZE=&quot;5&quot;><object classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot; codebase=&quot; width=&quot;228&quot; height=&quot;86&quot; id=ShockwaveFlash1>
<param name=movie value=&quot;./images/hemini_anim.swf&quot;>
<param name=quality value=high>
<embed src=&quot;./images/hemini_anim.swf&quot; quality=high pluginspage=&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;228&quot; height=&quot;86&quot;>
</embed>
</object></font>
</DIV>
<TABLE WIDTH=&quot;100%&quot; BORDER=&quot;0&quot;>
<TR>
<TD COLSPAN=&quot;3&quot; bgcolor=&quot;#CC9933&quot;><font face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><b>Login Request</b></font></td>
</TR>
</TABLE>

<FORM ID=PasswordRequestFrm ACTION=&quot;RequestPwdProcess.asp&quot; METHOD=&quot;GET&quot;>

<TABLE WIDTH=&quot;100%&quot;>
<TR>
<TD>
<DIV ALIGN=&quot;RIGHT&quot;>
<FONT>First Name : </FONT>
</DIV>
</TD>
<TD WIDTH=&quot;57%&quot;>
<INPUT NAME=&quot;FirstName&quot;>
</TD>
</TR>
<TR>
<TD>
<DIV ALIGN=&quot;RIGHT&quot;>
<FONT>Last Name : </FONT>
</DIV>
</TD>
<TD WIDTH=&quot;57%&quot;>
<INPUT NAME=&quot;LastName&quot;>
</TD>
</TR>
<TR>
<TD>
<DIV ALIGN=&quot;RIGHT&quot;>
<FONT>e-mail : </FONT>
</DIV>
</TD>
<TD WIDTH=&quot;57%&quot;>
<INPUT NAME=&quot;email&quot;>
</TD>
</TR>
<TR>
<TD>
<DIV ALIGN=&quot;RIGHT&quot;>
<FONT>Company : </FONT>
</DIV>
</TD>
<TD WIDTH=&quot;57%&quot;>
<INPUT NAME=&quot;CompanyName&quot;>
</TD>
</TR>
<TR>
<TD>
<DIV ALIGN=&quot;RIGHT&quot;>
<FONT>Phone # : </FONT>
</DIV>
</TD>
<TD WIDTH=&quot;57%&quot;>
<INPUT NAME=&quot;PhoneNumber&quot;>
</TD>
</TR>
<TR>
<TD>
<DIV ALIGN=&quot;RIGHT&quot;>
<FONT>Fax # : </FONT>
</DIV>
</TD>
<TD WIDTH=&quot;57%&quot;>
<INPUT NAME=&quot;FaxNumber&quot;>
</TD>
</TR>

</TABLE>
<P ALIGN=&quot;CENTER&quot;>
<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot; ID=SubmitPwdReq>
</P>
</FORM>
 
Hows this :

Code:
<html>
  <head>
    <script
      language=&quot;JavaScript&quot;
      type=&quot;text/JavaScript&quot;
    >
    <!--
        function formVal (form) {
            var valid = &quot; 0123456789&quot;;
            var temp;
            for (var x = 0; x < form.elements.length; x++) {
                elmt = form.elements[x];
                if (elmt.type != &quot;button&quot; &&
                    elmt.type != &quot;submit&quot; &&
                    elmt.type != &quot;hidden&quot; &&
                    elmt.type != &quot;select-one&quot; &&
                    elmt.type != &quot;select-multiple&quot; &&
                    elmt.value == &quot;&quot;) {
                    alert (&quot;Please fill in field: &quot; + 
elmt.name);
                    elmt.focus ();
                    return false;
                }
                if (elmt.name == &quot;PhoneNumber&quot; ||
                    elmt.name == &quot;FaxNumber&quot;) {
                    for (var i = 0; i < elmt.value.length; 
i++) {
                        temp = elmt.value.toLowerCase
().substring (i, i+1);
                        if (valid.indexOf (temp) == -1) {
                            alert (&quot;Please enter numbers 
only for field: &quot; + elmt.name);
                            elmt.focus ();
                            return false;
                        }
                    }
                }
            }
            return true;
        }
    //-->
    </script>
  </head>
<DIV ALIGN=&quot;LEFT&quot;><FONT FACE=&quot;Verdana, Arial, Helvetica, 
sans-serif&quot; SIZE=&quot;5&quot;><object classid=&quot;clsid:D27CDB6E-AE6D-
11cf-96B8-444553540000&quot;    
codebase=&quot;[URL unfurl="true"]http://download.macromedia.com/pub/shockwave/cabs/[/URL]
flash/swflash.cab#version=5,0,0,0&quot;; width=&quot;228&quot; height=&quot;86&quot; 
id=ShockwaveFlash1>
          <param name=movie value=&quot;./images/hemini_anim.swf&quot;>
          <param name=quality value=high>
          <embed src=&quot;./images/hemini_anim.swf&quot; 
quality=high pluginspage=&quot;[URL unfurl="true"]http://www.macromedia.com/shockwave/download/in[/URL]
dex.cgi?P1_Prod_Version=ShockwaveFlash&quot;; 
type=&quot;application/x-shockwave-flash&quot; width=&quot;228&quot; 
height=&quot;86&quot;>
          </embed>
        </object></font>
</DIV>
<TABLE WIDTH=&quot;100%&quot; BORDER=&quot;0&quot;>
    <TR>
        <TD COLSPAN=&quot;3&quot; bgcolor=&quot;#CC9933&quot;><font 
face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;><b>Login 
Request</b></font></td>
    </TR>
</TABLE>

<FORM
  ID=PasswordRequestFrm
  ACTION=&quot;RequestPwdProcess.asp&quot;
  METHOD=&quot;GET&quot;
  onSubmit=&quot;return formVal (this);&quot;
>

<TABLE WIDTH=&quot;100%&quot;>
    <TR>
        <TD>
            <DIV ALIGN=&quot;RIGHT&quot;>
                <FONT>First Name  :  </FONT>
            </DIV>
        </TD>
        <TD WIDTH=&quot;57%&quot;>
            <INPUT NAME=&quot;FirstName&quot;>
        </TD>
    </TR>
    <TR>
        <TD>
            <DIV ALIGN=&quot;RIGHT&quot;>
                <FONT>Last Name  :  </FONT>
            </DIV>
        </TD>
        <TD WIDTH=&quot;57%&quot;>
            <INPUT NAME=&quot;LastName&quot;>
        </TD>
    </TR>
    <TR>
        <TD>
            <DIV ALIGN=&quot;RIGHT&quot;>
                <FONT>e-mail  :  </FONT>
            </DIV>
        </TD>
        <TD WIDTH=&quot;57%&quot;>
            <INPUT NAME=&quot;email&quot;>
        </TD>
    </TR>
    <TR>
        <TD>
            <DIV ALIGN=&quot;RIGHT&quot;>
                <FONT>Company  :  </FONT>
            </DIV>
        </TD>
        <TD WIDTH=&quot;57%&quot;>
            <INPUT NAME=&quot;CompanyName&quot;>
        </TD>
    </TR>
    <TR>
        <TD>
            <DIV ALIGN=&quot;RIGHT&quot;>
                <FONT>Phone #  :  </FONT>
            </DIV>
        </TD>
        <TD WIDTH=&quot;57%&quot;>
            <INPUT NAME=&quot;PhoneNumber&quot;>
        </TD>
    </TR>
    <TR>
        <TD>
            <DIV ALIGN=&quot;RIGHT&quot;>
                <FONT>Fax #  :  </FONT>
            </DIV>
        </TD>
        <TD WIDTH=&quot;57%&quot;>
            <INPUT NAME=&quot;FaxNumber&quot;>
        </TD>
    </TR>

</TABLE>
<P ALIGN=&quot;CENTER&quot;>
    <INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot; ID=SubmitPwdReq>
</P>
</FORM>
Regards

David Byng

spider.gif


davidbyng@hotmail.com
 
awesome job on the code bigbaddave.
I would recommend doing this also for the phone and fax #'s
if (valid.indexOf (temp) == -1) {
alert (&quot;Please enter numbers only for field: &quot; + elmt.name);
} else { if (valid.indexOf (temp) < 7) {

7 being the minimum amount to make a valid phone #

I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
forgot to include the alert and another } at the end. don't forget that
if (valid.indexOf (temp) == -1) {
alert (&quot;Please enter numbers only for field: &quot; + elmt.name);
} else { if (valid.indexOf (temp) < 7) {
alert (&quot;Please enter a valid phone number!&quot;)
elmt.focus ();
return false;
}
}
}
}
}
return true;
}
//-->
</script> I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
once again I fall over my fingures. this will work I swear
if (elmt.name == &quot;PhoneNumber&quot; ||elmt.name == &quot;FaxNumber&quot;) {
for (var i = 0; i < elmt.value.length; i++) {
temp = elmt.value.toLowerCase().substring (i, i+1);
if (valid.indexOf (temp) == -1) {
alert (&quot;Please enter numbers only for field: &quot; + elmt.name);
elmt.focus (valid.indexOf (temp) == -1);
return false;
} else { if (elmt.value.length < 7) {
alert (&quot;Please enter a valid &quot; + elmt.name + &quot;!&quot;)
elmt.focus ();
return false;
}
}
}
}
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Hi David & 'Onpt'

Thanks to both of you for your help!

You have indicated above validating the telephone number and fax number. But, I would also like to validate and FORCE (mandatory) the user to fill out CompanyName, email, LastName and FirstName field as well.

Thanks.
 
Those are pointed out in David's script with the validation of
if null or &quot;&quot; alert them
copy his code and if you want the phone number length validation I suggested you can place that in there also I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Hi,

I have the following fields in the code above:

the telephone number and fax number (validate for numbers)

CompanyName, email, LastName and FirstName (validate to force the user to fill these fields out and validate if the email ends with @)

I think the reason the code you suggested above didn't work is that there no validation being done in submit button, OnClick() or something to that extent?

Again thanks very much for your input!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top