在应用程序中,我们经常遇到一些文本框是禁止录入某些信息的。比如注册窗口,我们必须要填写必要的信息,而在填写的时候又有相应的要求,比如只能输入英文或者数字,字符不能小于8位等等要求。
下面小试牛刀,来禁止某个字符的输入。请留意下面的函数
Public Function ForbitChr(MyTextbox As TextBox, mySymbo As String) As String '在文本里禁止使用某个字符
If CountChr(MyTextbox.Text, mySymbo) > 0 Then
Select Case MsgBox("不允许输入<" & mySymbo & ">字符。", vbYes, "提示:")
End Select
MyTextbox = Replace(MyTextbox.Text, mySymbo, "")
MyTextbox.SelStart = Len(MyTextbox.Text)
End If
End Function