Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 4th, 2003, 02:32 AM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default Checking for a number

Hi

In asp (form validation is server side) how can I check that a form field (quantity in a shopping basket) is a number and not a text value? Is isnum a valid vbscript command?

Regards

Andy Green
Reply With Quote
  #2 (permalink)  
Old June 4th, 2003, 02:41 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

There are a number of ways you can do this depending upon how you pass the variables.

1, Validate on the same form with javascript

You can use a javascript function to check the data type and then open an alert box if data is not valid. You will find lots of examples if you type javascript form validation into google.

2, passing variables in the querystring

Here you can call the same asp page when the form is submitted, but add a flag either as a hidden field in the form or in the querystring to show the form has been submitted. You can then validate the data as the form reloads. If successful you can use the redirect command to go to the next page, passing the values in the querystring.

3, Validate on the receiving page.

You can validate on the next page and then write the error statement asking the users to 'go back' to correct the entry.

Hope this helps
Reply With Quote
  #3 (permalink)  
Old June 4th, 2003, 03:07 AM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thanx for trying to help.

What I'm doing is this - I have a shopping cart (I've had to write my own rather than use a commercial one to get some specific functionality) The form submits to itself and I pass through the querystring the form values.

I'm validating the form values ie checking that there is a value in various form fields in asp as the page loads.

I'm stuck on how to check that the qty value is a number and not text - I could do this client side with javascript but that would mean I'd have 2 validation routines, one client side and one server. If I have to move all validation client side I could, but if there is a simple solution to check for a number server side it would suit me better.

Regards

Andy G
Reply With Quote
  #4 (permalink)  
Old June 4th, 2003, 03:23 AM
Authorized User
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Andy

Using VBScript you can use the IsNumeric vb function to check for a number.
e.g.
Dim intNum
intNum = 5

'use
If IsNumeric(intNum) Then
   ...
End If

or

Dim intBasketQty
intBasketQty = Trim(Request.Form("txtBasketQty"))

If IsNumeric(intBasketQty) Then
   ... 'do something here
End If

Hope this helps

Quote:
quote:Originally posted by aware
 Hi

Thanx for trying to help.

What I'm doing is this - I have a shopping cart (I've had to write my own rather than use a commercial one to get some specific functionality) The form submits to itself and I pass through the querystring the form values.

I'm validating the form values ie checking that there is a value in various form fields in asp as the page loads.

I'm stuck on how to check that the qty value is a number and not text - I could do this client side with javascript but that would mean I'd have 2 validation routines, one client side and one server. If I have to move all validation client side I could, but if there is a simple solution to check for a number server side it would suit me better.

Regards

Andy G
Reply With Quote
  #5 (permalink)  
Old June 4th, 2003, 03:39 AM
Authorized User
 
Join Date: Jun 2003
Location: Bromsgrove, Worcestershire, United Kingdom.
Posts: 59
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx Nidgep

Thats exactly what I want.

I was trying to use Isnum rather than Isnumeric.

Great.
Reply With Quote
  #6 (permalink)  
Old June 5th, 2003, 09:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Sydney, NSW, Australia.
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
Default

For future reference, you can download the Windows Script (including VBScript) documentation from:
http://www.microsoft.com/downloads/d...displaylang=en
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation For Phone Number and Mobile Number dhruthi.ram99 Javascript How-To 12 October 30th, 2011 07:24 AM
Checking an ICQ number SKYDOS BOOK: Beginning Regular Expressions 3 November 9th, 2008 03:55 PM
datatype checking stolte XSLT 1 March 20th, 2008 06:45 PM
Checking Processes AggressiveFish Beginning VB 6 0 September 19th, 2006 01:29 PM
Checking for upper,lower case, number and symbol dumbdumb SQL Server 2000 1 March 18th, 2004 03:51 AM



All times are GMT -4. The time now is 10:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.