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...
============================================================
============================================================
Here is the form code...
============================================================
============================================================
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
Here is the validation code to review...
============================================================
Code:
<%
' Reset Variables
ErrMsg = ""
Crew = ""
If Request.QueryString("action") = "" Then
'
' Show the form - the form has not yet been submitted
'
Else
If Request.Form("crew") = "" Then
'
' No crew number was supplied
'
ErrMsg = "<font color=RED><b>ERR-001: No crew number was entered</b></font>"
ElseIf NOT IsNumeric(Request.Form("crew")) Then
'
' Crew number supplied was Not A Number (NaN)
'
ErrMsg = "<font color=RED><b>ERR-002: Crew number can be numbers only</b></font>"
ElseIf NOT Len(Request.Form("crew") = 4) Then
'
' Crew number was <> 4 numbers
'
ErrMsg = "<font color=RED><b>ERR-003: Crew number must be no less or greater than 4 digits - " & Request.Form("crew") & "</b></font>"
Else
'
' Send values to Oracle - the form has been completed and then submitted
'
Response.Redirect("[URL unfurl="true"]http://dot0dta1asodev5.mdot.w2k.state.me.us:7778/devmats/reports.mtrl_usage?crew="[/URL] & Request.Form("crew") & "&mtrl=" & Request.Form("mtrl"))
End If
End If
%>
Here is the form code...
============================================================
Code:
<%
If ErrMsg <> "" Then
Response.Write(ErrMsg)
End If
%>
<form action="[URL unfurl="true"]http://mdotweb<%=[/URL] Request.ServerVariables("PATH_INFO") %>?action=validate" method="post" name="mtrl_usage" id="mtrl_usage">
<table width="50%" border="0" cellspacing="5" cellpadding="0">
<tr valign="top">
<td width="27%" nowrap><div align="right"><strong>4 digit Crew Number: </strong></div></td>
<td width="3%" rowspan="4" nowrap><strong> </strong></td>
<td width="14%" nowrap><input name="crew" type="text" id="crew" value="<%= Request.Form("crew") %>" size="11" maxlength="4"> </td>
<td width="56%" nowrap><div align="right"><em><strong>Example:</strong></em> Division 1 = 1000<br>
District 13 = 1300<br>
Crew 1321 = 1321 </div></td>
</tr>
<tr valign="top">
<td colspan="4" nowrap><div align="center"> <br>
<input type="submit" name="Submit" value="Submit">
</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