如何限制只能输入数字或只能输入汉字,和只能输入5个数字
如何限制只能输入数字或只能输入汉字,和只能输入5个数字
Public Function fun_len(ByVal key As String, ByVal leng As Long) As Boolean If Len(Trim(key)) = leng Then fun_len = True Else fun_len = False End If Exit Function '判断是否为数字 If IsNumeric(YourText.Text) = False Then MsgBox "请输入数字", vbOKOnly + vbQuestion, "提示" YourText.SetFocus Exit Sub End If '判断是否为5位 If fun_len(YourText.Text, 5) = False Then MsgBox "请输入5位...", vbOKOnly + vbQuestion, "提示" YourText.SetFocus Exit Sub End If
'判断是否为中文 For i = 1 To Len(YourText.Text) '如果发现有中文 If Asc(Mid((YourText.Text), i, 1)) < 0 Then ......