programming-examples/asp/More_Code_Snippets/Validate numerical data example.asp
2019-11-18 14:25:58 +01:00

29 lines
889 B
Plaintext

<form method="post" action ="<%= Request.ServerVariables("SCRIPT_NAME") %>" >
<input type ="text" name="age"><br>
<input type="submit">
</form>
<%
Dim strAge , intAge , blnValid
If Request.ServerVariables("CONTENT_LENGTH") <> 0 Then
strAge = Trim(Request.form("age"))
'if strAge is a number then we go on
If isNumeric(strAge) Then
'convert strAGe to an integer
intAge = CInt(strAge)
' if age is between 1 and 120 then success
If 1<= intAge and 120 >= intAge Then
blnValid = True
End If
'if a number is entered then display this
Else
Response.Write "You didnt enter a valid number<br>"
End If
'if you have a valid number then display a message
If blnValid = True Then
Response.Write("Your age is " & intAge)
'if number is invalid then display a different message
Else
Response.Write("Enter an age between 1 and 120 ")
End If
End If
%>