Checking for numbers

1. Senior Member
Join Date
Dec 1969
Posts
213

## Checking for numbers

I am writting a form check and need to figure out an easy way to check if certain filds have only numbers (which is what they are supposed to have). (I am using ASP)

2. oli
Senior Member
Join Date
Dec 1969
Posts
3,961

## RE: Checking for numbers

&#060;%<BR>If IsNumeric(expression) Then<BR> Response.write "Is a number"<BR>Else<BR> Response.write "Is not a number"<BR>End If<BR>%&#062;<BR>

3. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Checking for numbers

&#060;%<BR>expression = "02e2"<BR>If IsNumeric(expression) Then<BR> Response.write "Is a number"<BR>Else<BR> Response.write "Is not a number"<BR>End If<BR>%&#062;<BR><BR>Will show "Is a number". :-)<BR><BR>Craig.

4. oli
Senior Member
Join Date
Dec 1969
Posts
3,961

## RE: Checking for numbers

Hmm cause it&#039;s Hex?<BR><BR>Do you have to iterate through each character and check then?<BR><BR>But then surely &#039;e&#039; on its own is as much as as number as &#039;2&#039; with that logic?

5. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: Checking for numbers

Not hex. "e" is a mathematical symbol meaning "*10^".<BR><BR>So:<BR>"20e2" means "20*10^2" means "20*100" means "2000".<BR><BR>So, technically, it&#039;s a number.<BR><BR>What I was trying to show was that a "number" to one person may not be a "number" to another. He needs to DEFINE what he wants to allow - is it just integers, is it any floating-point number, does he want to allow mathematical expressions...?<BR><BR>IsNumeric&#039;s a nice little function, but it does have it&#039;s drawbacks is all I&#039;m saying.<BR><BR>Craig.

6. oli
Senior Member
Join Date
Dec 1969
Posts
3,961

## I see. (eop)

.

7. Senior Member
Join Date
Dec 1969
Posts
787

## RE: I see. (eop)

I generally loop through strings and look for character codes outside the range 48 to 57.

8. Member
Join Date
Dec 1969
Posts
36

## RE: I see. (eop)

BUT you can do this form validations in client side itself.

9. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: I see. (eop)

Of course you can, but:<BR>1) You still have the same problems - if you don&#039;t define what KIND of number you&#039;re checking for, you&#039;ll have the same problems as oli/pill/I showed here.<BR>2) You still have to back it up with server-side validation! What if someone has client-side scripting turned off? Or, more sinisterly, they purposefully submit bad values to break your code.<BR><BR>Validation should be done everywhere possible, however, server-side validation is MUCH more important than client-side validation.<BR><BR>Craig.

10. Member
Join Date
Dec 1969
Posts
36

## RE: I see. (eop)

Yeaa&#039; thats one nice. thanks. If the COOkies is turned off in the browser. Is it possible to keep a seesion.?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•