Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Number validation vbscript

Posted on 2007-12-03
8
Medium Priority
?
2,048 Views
Last Modified: 2010-04-21
I've got an old school web page that was built for us many years back. It has an insert page and a submit page that validates some fields and then fowards them to our sql server. Currently it validates if the field is filled in with text or numeric, but I need it to validate for numerics only. Below is the actual text where the validation occurs. Any help would be appreciated.

Dim annual_quantity_n
annual_quantity_n = Replace(Request("annual_quantity_n"),"'","''")
Validate annual_quantity_n,"Annual Quantity"

Zach
0
Comment
Question by:zneria
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 20401229
try use IsNumeric function to check whether a value is numeric or not, like:

...
if isnumeric(yourValue) = false then
    msgbox "The value is not numeric"
    exit sub
end if
..
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 20401235
if is in ASP, something similar:

...
if isnumeric(yourValue) = false then
    response.write "The value is not numeric"
  '...
end if
..
0
 
LVL 28

Accepted Solution

by:
sybe earned 1000 total points
ID: 20401842
The Classic ASP function IsNumeric fails in 2 instances:

If the parameter is Null, then it returns True, which obviously is not what you want and if the typename is Decimal (which happens sometimes with values reurned from a database), it returns False, which again is the wrong result. See below for a replacement function.

I also suspect that you need an Integer (although I am not sure).

================================

> if isnumeric(yourValue) = false then

I find this a quite remakarble line. Normally one would write

If Not IsNumeric(somevalue) Then

=============================






If IsNumeric2(Request("annual_quantity_n")) Then
    AnnualQuantity = Clng(Request("annual_quantity_n"))
Else
   ' not a numeric value, do what you need to do
 
End If
 
 
Function IsNumeric2(ByVal var)
    Select Case VarType(var)
        Case 0: IsNumeric2 = False
        Case 14: IsNumeric2 = True
        Case Else: IsNumeric2 = IsNumeric(var)
    End Select
End Function

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Ryan Chong
ID: 20401892
>>Normally one would write..

that's depends on how a developer write the syntax, which basically both working fine...
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 20404236
If its user input you should have clent side Javascript validation

http://www.google.com/search?q=numbers+only++with+isNaN&hl=en&safe=active
0
 
LVL 1

Author Comment

by:zneria
ID: 20404395
Sybe I'll go ahead and try this out on the submit page. Jitganguly I'm aware of the javascript however I didn't build these pages and I need it to be vbscript on the submit page, not the input page. Thanks for the 411 though.
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 20404414
>>Thanks for the 411 though.
:-). It was 555 1212 :-)

Good luck
0
 
LVL 1

Author Closing Comment

by:zneria
ID: 31412536
Sybe,
The code worked like a charm. Can't thank you enough man =)

Zach
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question