Public Function CheckForNumChar(Text As String) As Boolean
摘要:此函数检查字符是否为NUMERIC字符
输入参数:Char =要检查的字符
输出参数:如果是数字则为True,如果不是数字则为False
Dim Length, prompt, Char As String
Dim response
Dim I As Integer
Length = Len(Text) 'Check length of string
For I = 1 To Length Step 1
CheckForNumChar = ((Mid(Text, I, Length) Like "[0-9]*")) 'Checks for number
`enter code here`If CheckForNumChar Then
Else 'Character is not Numeric
prompt = "Only Numeric Characters Are Permitted In This Field" 'MsgBox string
response = MsgBox(prompt, vbOKOnly + vbExclamation, "Character
Check") 'MsgBox
SendKeys "{Bs}", True 'Backspace
Exit Function
End If
Next I
End Function
答案 0 :(得分:1)
将[0-9]*
更改为[A-Za-z0-9]*
。
供参考:https://msdn.microsoft.com/en-us/library/swf8kaxw.aspx?f=255&MSPPError=-2147217396
多个角色范围
要为同一个字符位置指定多个范围,请将它们放在不带分隔符的相同括号中。例如,如果字符串中相应的字符位置包含A-C范围或X-Z范围内的任何字符,[A-CX-Z]将产生匹配。