vb代码 利用正则表达式限制Text只能输入中文字符?
发布网友
发布时间:2023-07-15 09:35
我来回答
共1个回答
热心网友
时间:2024-04-11 18:40
Private Function RegExpTest(StrText, Pattern)
Dim regex
Set regex = CreateObject("VBScript.RegExp")
regex.Pattern = Pattern
regex.Global = True
RegExpTest = regex.Test(StrText)
Set regex = Nothing
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 8 And Not RegExpTest(Chr(KeyAscii), "[\u4e00-\u9fa5]") Then
KeyAscii = 0
End If
End Sub