سؤال

Is there a function like IsNumeric() in VBScript to check if a string contains only alphanumeric (a-zA-Z0-9) characters? Or can this only be determined by regular expressions?

هل كانت مفيدة؟

المحلول

Use the ^ feature (not in class) of RegExps to search for characters not in (a-zA-Z0-9):

>> Set r = New RegExp
>> r.Pattern = "[^a-zA-Z0-9]"
>> For Each t In Array("aA0", "a.0")
>>     WScript.Echo t, CStr(r.Test(t))
>> Next
>>
aA0 False
a.0 True
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top