Solved

Number validation vbscript

Posted on 2007-12-03
8
2,041 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

630 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