Active Server Pages Programming (ASP)/ASP (field datatype)

Advertisement


Question
i'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...:(


Answer
Hi

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

Active Server Pages Programming (ASP)

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

I can answer any kind of questions in ASP.NET, C#, VB.NET, SharePoint 2007, ASP, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder.

©2012 About.com, a part of The New York Times Company. All rights reserved.