best way to determine if a string contains only the digits 0- 9

What is the best way to determine if a string contains only the digits 0 to 9.

IsNumeric() doesn't seem to be sufficent, and I'd like to avoid looping through each character, but if that's the only way I guess I'll have to .

(would be easy in perl, but that doesn't help me either ;)

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dim s as string

if Asc(s) >= 48 and Asc(s) <= 57 then
  msgbox "it is between 0 and 9"
end if
you could use a regular expression object to test for your pattern,,,
Will write a little function here and post in a bit....
Hi josephfluckiger,
Agree with mccainz2.
Regular expressions suits this very well, specially since you have perl experience

for a link to MS site where you can download regex library

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Another way to do it is using Val

If trim(Val(sText)) = Trim(sText) then...


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dim objRXP As New RegExp
    objRXP.Pattern = "^\d[\d]*\d$"
    If objRXP.Test("1444444444") Then
        MsgBox "match"
    End If
Definitely check my Pattern , I am EXTREMELY rusty with patterns ... tested on just a few so be wary...
To use the object simply add a reference to Microsoft VBscript Regualr Expressions
Why not plainly "\d+" ?
\d = digit
+ = one or more

josephfluckigerAuthor Commented:
mccainz2, you mean I can have my cake and eat it too! that's fantastic, thanks so much for showing me how to do regx in VB.

Daba's answer does the trick.
ended up doing this trick, since I don't even want 0.3, for example, to be a valid entry.

thanks so much all, all your responses were VERY helpful!
> add a reference to Microsoft VBscript Regualr Expressions
So that is where they are!

I was looking for Microsoft Regular Expressions, and could not find it!

Why not plainly "\d+" ?

That pattern will match any string as long as it has one or more numbers in it ... example "sssssss1a" will return as a match
josephfluckigerAuthor Commented:
yea, I've worked with Perl reg expressions for three years, and VB for one. I've always wanted reg expressions in VB, this great guys, thanks.
What about "^\d+$" ?
I only "discovered" regex about a week ago!

I know what you mean!
I havent used in em about a year and its practically like I never used them before!!!
I'm sure theres a better expression for the task but at this time of night it's beyond me :)
"^\d+$"  looks like that one works!
Sometimes I am a fast learner!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.