Active Server Pages Programming (ASP)/ASP (field datatype)
Expert: Srini Nagarajan - 11/26/2004
Questioni'm doing my final year project now and must present the project in this coming week.
my problem is..
i'm using html and classic ASP and connect to MS ACCESS database..
here.. i want to do a validation for field name PRICE where we must put the datatype to verify it..
here is the source code for validation that i found :
------------------------
<%
DIM strPrice
strPrice = Request.Form("Price")
IF strPrice <> "" THEN
response.write("Invalid datatype!")
else
response.write("Ok!")
end if
%>
-----------------------
the problem is at "IF strPrice <> "" " what datatype that i must put here and to differentiate either the input entered by user are integer or not(character)? im try to put INT, STRING but still cannot work..
what datatype i must put here?
pleas help me ASAP..
bcoz i must finish this project to let me grad this year...
TQ...:(
AnswerHi
Why don't you validate the Price on the client side instead of Server side.. Here is the code for validating on the client side
<SCRIPT language="JavaScript">
<!--
function IsNumeric(strString)
// check for valid numeric strings
{
var strValidChars = "0123456789.-";
var strChar;
var blnResult = true;
if (strString.length == 0) return false;
// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}
// -->
</SCRIPT>
Such a function can be used as follows to check a field and return an error message if the contents are not numeric:
if (document.frmUser.afield.value.length == 0)
{
alert("Please enter a value.");
}
else if (chkNumeric(document.frmUser.afield.value) == false)
{
alert("Please check - non numeric value!");
}
If you want to use ASP
try like this
IF cint(strPrice) > 0 THEN
OKAY
else
NOT OKAY
end if
Happy Programming!
-Srini