Solved

Number validation vbscript

Posted on 2007-12-03
8
2,034 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 52

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 52

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 250 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
Industry Leaders: 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 52

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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