3

I'm working on a Windows application that's written in VBScript and I need to check a string for any non-numeric characters, specifically anything a-z. I realize I could probably do this using the InStr() function in conjunction with a loop that checks for a-z but that just seems ridiculous. I have very little experience in VBScript so I really don't know where to go on this.

What's a good method for handling this kind of situation?

donut
  • 9,427
  • 5
  • 36
  • 53

3 Answers3

8

Use a regular expression:

Set re = New RegExp
re.Pattern = "[a-z]"
re.IgnoreCase = True
re.Global = True
hasMatches = re.Test("12345abc")

If hasMatches = True Then
    ' it has letters
End If
Gareth Davidson
  • 4,857
  • 2
  • 26
  • 45
2

The IsNumeric function?

If IsNumeric(x) Then y = CDbl(x)
Tmdean
  • 9,108
  • 43
  • 51
1

a little late but an answer.

if you work with isnumeric and you set a Not in front to check if there is NO NUMBER. But every sign like !"§$%& and so on will be ignored and will be put into the check

answerman
  • 11
  • 1