can ASP check if an object is an integer?

L

Lord Merlin

Sorry for the dumb question, but what is the function in ASP to see if an
object / string is an integer?

I want to check the contents of a form, and if it's an integer, i.e a
number, do something, else if it's a word do something else, and I'm not
sure howto?

--


Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
 
S

Steven Burn

If IsNumeric(String_To_Check) Then
'// True
'// Do something
Else
'// False
'// Do something else
End If

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
L

Lord Merlin

Aha, thanx very much :)

btw, is there a manual / website with all the classis ASP commands /
functions / etc?

--


Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
| If IsNumeric(String_To_Check) Then
| '// True
| '// Do something
| Else
| '// False
| '// Do something else
| End If
|
| --
|
| Regards
|
| Steven Burn
| Ur I.T. Mate Group
| www.it-mate.co.uk
|
| Keeping it FREE!
|
|
| | > Sorry for the dumb question, but what is the function in ASP to see if
an
| > object / string is an integer?
| >
| > I want to check the contents of a form, and if it's an integer, i.e a
| > number, do something, else if it's a word do something else, and I'm not
| > sure howto?
| >
| > --
| >
| >
| > Kind Regards
| > Rudi Ahlers
| > +27 (82) 926 1689
| >
| > Greater love has no one than this, that he lay down his life for his
| friends
| > (John 15:13).
| >
| >
|
|
 
L

Lord Merlin

Ok, one more question, how do I use this, if I want to checkif it's not an
integer.

I want to check two things, like so:

if company_count = 0 and Is(not?)Numeric(industry) then
// stuff here
end if

i.e. If company_count = 0, and industry is not an integer?
--


Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
| If IsNumeric(String_To_Check) Then
| '// True
| '// Do something
| Else
| '// False
| '// Do something else
| End If
|
| --
|
| Regards
|
| Steven Burn
| Ur I.T. Mate Group
| www.it-mate.co.uk
|
| Keeping it FREE!
|
|
| | > Sorry for the dumb question, but what is the function in ASP to see if
an
| > object / string is an integer?
| >
| > I want to check the contents of a form, and if it's an integer, i.e a
| > number, do something, else if it's a word do something else, and I'm not
| > sure howto?
| >
| > --
| >
| >
| > Kind Regards
| > Rudi Ahlers
| > +27 (82) 926 1689
| >
| > Greater love has no one than this, that he lay down his life for his
| friends
| > (John 15:13).
| >
| >
|
|
 
L

Lord Merlin

Thanx :)

--


Kind Regards
Rudi Ahlers
+27 (82) 926 1689

Greater love has no one than this, that he lay down his life for his friends
(John 15:13).
| If Not IsNumeric(industry) Then
|
| '---- Do Stuff
|
| End If
|
| Bob Lehmann
|
| | > Ok, one more question, how do I use this, if I want to checkif it's not
an
| > integer.
| >
| > I want to check two things, like so:
| >
| > if company_count = 0 and Is(not?)Numeric(industry) then
| > // stuff here
| > end if
| >
| > i.e. If company_count = 0, and industry is not an integer?
| > --
| >
| >
| > Kind Regards
| > Rudi Ahlers
| > +27 (82) 926 1689
| >
| > Greater love has no one than this, that he lay down his life for his
| friends
| > (John 15:13).
| > | > | If IsNumeric(String_To_Check) Then
| > | '// True
| > | '// Do something
| > | Else
| > | '// False
| > | '// Do something else
| > | End If
| > |
| > | --
| > |
| > | Regards
| > |
| > | Steven Burn
| > | Ur I.T. Mate Group
| > | www.it-mate.co.uk
| > |
| > | Keeping it FREE!
| > |
| > |
| > | | > | > Sorry for the dumb question, but what is the function in ASP to see
if
| > an
| > | > object / string is an integer?
| > | >
| > | > I want to check the contents of a form, and if it's an integer, i.e
a
| > | > number, do something, else if it's a word do something else, and I'm
| not
| > | > sure howto?
| > | >
| > | > --
| > | >
| > | >
| > | > Kind Regards
| > | > Rudi Ahlers
| > | > +27 (82) 926 1689
| > | >
| > | > Greater love has no one than this, that he lay down his life for his
| > | friends
| > | > (John 15:13).
| > | >
| > | >
| > |
| > |
| >
| >
|
|
 
B

Bob Barrows [MVP]

Lord said:
Sorry for the dumb question, but what is the function in ASP to see
if an object / string is an integer?

I want to check the contents of a form, and if it's an integer, i.e a
number, do something, else if it's a word do something else, and I'm
not sure howto?

Everone has been recommending IsNumeric(), but that function is flawed. What
do you guess will be returned by:

Response.Write IsNumeric("1e2")

Try it, I'll wait.


Surprised? Try "1d2".

The explanation is that e and d are exponent indicators. Try CDbl("1d2") and
see what you get ....

100, right? "d" and "e" aren't the only characters that can cross you up.
Depending on the locale, some characters can be used for currency symbols
and thus will also be passed by IsNumeric(), which only verifies that a
string can be converted to at least one of the many numeric subtypes
(including currency, double, single and integer).

The real solution is to use a regular expression to verify that the string
contains only the characters 0-9 (you could use on error resume next and
CInt(), checking for an error on the following line, but it's silly to raise
an error for this purpose).

I just got called away, so somebody else is going to have to show you the
reg exp to use for this task. Chris Hohmann, are you out there? :)

Bob Barrows
 
C

Chris Hohmann

Bob Barrows said:
The real solution is to use a regular expression to verify that the string
contains only the characters 0-9 (you could use on error resume next and
CInt(), checking for an error on the following line, but it's silly to raise
an error for this purpose).

I just got called away, so somebody else is going to have to show you the
reg exp to use for this task. Chris Hohmann, are you out there? :)

Positive Integer Without Separator:
^\d{1,5}$

Positive Integer With Separator:
^(\d{1,2},\d{3}|\d{1,3}$

Positive/Negative Without Separator:
^-?\d{1,5}$

Positive/Negative With Separator
^-?(\d{1,2},\d{3}|\d{1,3})$


You may need to adjust the above if your locale uses something other than
comma as the thousands separator. Also, you'll want to check for integer
overflow errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top