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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Validation problem

Status
Not open for further replies.

cmitsys

Technical User
Oct 31, 2003
14
I have a field 'crew' on a form that must always be a 4 digit number, but I am having problems with the validation.

Here is the validation code to review...

============================================================
Code:
<%
' Reset Variables
ErrMsg = &quot;&quot;
  Crew = &quot;&quot;

If Request.QueryString(&quot;action&quot;) = &quot;&quot; Then
	'
	' Show the form - the form has not yet been submitted
	'
Else
	If Request.Form(&quot;crew&quot;) = &quot;&quot; Then
		'
		' No crew number was supplied
		'
		ErrMsg = &quot;<font color=RED><b>ERR-001: No crew number was entered</b></font>&quot;
	ElseIf NOT IsNumeric(Request.Form(&quot;crew&quot;)) Then
		'
		' Crew number supplied was Not A Number (NaN)
		'
		ErrMsg = &quot;<font color=RED><b>ERR-002: Crew number can be numbers only</b></font>&quot;
	ElseIf NOT Len(Request.Form(&quot;crew&quot;) = 4) Then
		'
		' Crew number was <> 4 numbers
		'
		ErrMsg = &quot;<font color=RED><b>ERR-003: Crew number must be no less or greater than 4 digits - &quot; & Request.Form(&quot;crew&quot;) & &quot;</b></font>&quot;
	Else
		'
		' Send values to Oracle - the form has been completed and then submitted
		'
		Response.Redirect(&quot;[URL unfurl="true"]http://dot0dta1asodev5.mdot.w2k.state.me.us:7778/devmats/reports.mtrl_usage?crew=&quot;[/URL] & Request.Form(&quot;crew&quot;) & &quot;&mtrl=&quot; & Request.Form(&quot;mtrl&quot;))
	End If
End If
%>
============================================================

Here is the form code...

============================================================
Code:
      <%
	  If ErrMsg <> &quot;&quot; Then
	  	Response.Write(ErrMsg)
	  End If
	  %>
       <form action=&quot;[URL unfurl="true"]http://mdotweb<%=[/URL] Request.ServerVariables(&quot;PATH_INFO&quot;) %>?action=validate&quot; method=&quot;post&quot; name=&quot;mtrl_usage&quot; id=&quot;mtrl_usage&quot;> 
        <table width=&quot;50%&quot;  border=&quot;0&quot; cellspacing=&quot;5&quot; cellpadding=&quot;0&quot;> 
          <tr valign=&quot;top&quot;> 
            <td width=&quot;27%&quot; nowrap><div align=&quot;right&quot;><strong>4 digit Crew Number: </strong></div></td> 
            <td width=&quot;3%&quot; rowspan=&quot;4&quot; nowrap><strong>   </strong></td> 
            <td width=&quot;14%&quot; nowrap><input name=&quot;crew&quot; type=&quot;text&quot; id=&quot;crew&quot; value=&quot;<%= Request.Form(&quot;crew&quot;) %>&quot; size=&quot;11&quot; maxlength=&quot;4&quot;> </td> 
            <td width=&quot;56%&quot; nowrap><div align=&quot;right&quot;><em><strong>Example:</strong></em> Division 1 = 1000<br> 
                District 13 = 1300<br> 
                Crew 1321 = 1321 </div></td> 
          </tr> 
          <tr valign=&quot;top&quot;> 
            <td colspan=&quot;4&quot; nowrap><div align=&quot;center&quot;> <br> 
                <input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;> 
              </div></td> 
          </tr> 
        </table> 
      </form>
============================================================

What happens is that if you enter a number <4 the error message (ERR-003) appears, likewise if the message ins not a pure numeric value then ERR-002 is displayed. This part of the code appears to be working great.

The problem is that if you entered 3 digits and get ERR-003 then correct it by entering 4 digits, you still get told that it must be 4 digits, it is like the len() condition is not rechecking and allowinf the form to submit.

Any ideas why, or better still know of a snippet of code that is correctly validating that I can use.

Thank you,
Charlie
 
Change the following statement

ElseIf NOT Len(Request.Form(&quot;crew&quot;) = 4) Then

to this

ElseIf NOT (Len(Request.Form(&quot;crew&quot;)) = 4) Then
 
Hey... =o)

It appears to have fixed the problem - thnx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top