how to check if string only contains numbers

  • Thread starter Thread starter Amorax
  • Start date Start date
A

Amorax

How can I check if a string only contains numbers and no other symbols?

Richard
 
John said:
IsNummeric()

That won't necessarily give the desired result, since IsNumeric will,
for example, return True for "-$23E01" . If you really want only the
digits 0-9 in the string, you can test it with a function like this:

'----- start of code -----
Function IsAllDigits(CheckString As String) As Boolean

If CheckString Like "*[!0-9]*" Then
IsAllDigits = False
Else
IsAllDigits = True
End If

End Function

'----- end of code -----
 

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

Back
Top