...

View Full Version : How I can check(validate) if this var is an integer and appear appropriate message



lse123
06-17-2007, 09:38 AM
ASP/VBSCRIPT
When I fill a field in an html form , and this want to be an integer ... well when I get this with POST to an asp document, How I can check(validate) if this is an integer and appear appropriate message if it is not ?

entry=6778 or "78yut" or "khgdds"
<%
...
string = request.form("entry")
int = Cint(string)
If (not(isNumeric(int))) then
response.write "Please enter a number"
response.end
end if
...
%>

if entry="string" may avoid error [I will have error here ?] in
int = Cint(string)
?

mehere
06-17-2007, 04:07 PM
check for isNumeric to see if it's a number

strEntry = request.form("entry")
if Not isNumeric(strEntry) Then
response.Write("Please enter a number")
else
--whatever you do if it's a number
end if

miranda
06-17-2007, 06:55 PM
string = request.form("entry")
int = Cint(string)


The reason that will throw an error is because you didn't checked to make sure if it was a numeric value until after you tried to convert the incoming form field to the integer.

the function cint is used to convert a number to an integer.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum