Private Sub PoText_KeyPress(KeyAscii As Integer) If KeyAscii >= -20319 And KeyAscii <= -3652 Or KeyAscii = 8 Then
Else
KeyAscii = 0
End If
End Sub我是这样做的
但在中文输入法下一样可以输入数字和字母
我应该怎么做才能让它只输入汉字?
Else
KeyAscii = 0
End If
End Sub我是这样做的
但在中文输入法下一样可以输入数字和字母
我应该怎么做才能让它只输入汉字?
If Len(Text1.Text) * 2 <> LenB(StrConv(Text1.Text, vbFromUnicode)) Then
MsgBox "Please input Chinese Characters"
Cancel = True
End If
End Sub
Private Sub PoText_KeyPress(KeyAscii As Integer) If KeyAscii > 0 Then KeyAscii = 0 Select Case KeyAscii
Case -23632 To -23623, -23615 To -23590,-23583 To -23558
KeyAscii = 0
End SelectEnd Sub
Dim sText As StringFunction bMatching(s As String, p As String) As Boolean
'参数:s要匹配的字符串,p正则表达式
On Error GoTo 100
Dim myReg As RegExp
Set myReg = New RegExp
bMatching = False
myReg.IgnoreCase = True
myReg.Pattern = p
bMatching = myReg.Test(s)
Exit Function
100:
bMatching = False
End FunctionPrivate Sub Text2_Change()
Dim p As String
p = "^[\u4e00-\u9fa5]{0,}$"
If bMatching(Text2, p) Then
sText = Text2
Else
Text2 = sText
Text2.SelStart = Len(Text2)
End If
End Sub
是的,我想把全角的数字和字母也禁止
现在还是不行
有没有办法?
Private Sub Text1_Change()
Dim i As Long
For i = 0 To 25
Text1.Text = Replace(Text1.Text, Chr(i + 65), "", , , vbTextCompare)
Next
End Sub
评注:匹配中文还真是个头疼的事,有了这个表达式就好办了匹配双字节字符(包括汉字在内):[^\x00-\xff]
评注:可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1)用正则表达式限制只能输入全角字符:/[^\uFF00-\uFFFF]/g