如何检查在文本框里输入的字符符合规定?我想通过配置文件规定在文本框中输入的字符一定要符合要求,
如我在配置文件中 MASK=??YN??
这样我在文本框中输入的字符也要就按它的规定,如11YN11,12YN11,67YN89等等.
如果我输入的字符是158893,1233560112等等的就不能提交.不知那位大侠能帮帮我?
万分感谢!!!

解决方案 »

  1.   

    Private Sub Command1_Click()
     If Text1.Text Like "[0-9][0-9][A-Z][A-Z][0-9][0-9]" Then
       Else
         MsgBox "not match"
     End If
    End Sub
      

  2.   

    多种方法:
    1 "工程" - "部件",选择Microsoft Masked Edit Control 6.0,添加MaskedEdit控件。在窗体上加入此控件,将Mask属性设置为##YN##。2 仍用普通文本框(maxlength=6),在keypress事件中处理:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    Select Case Text1.SelStart
    Case 0, 1, 4, 5
        Select Case KeyAscii
            Case 8, 9, 13, Asc("0") To Asc("9")
            Case Else
                KeyAscii = 0
        End Select
    Case 2
        KeyAscii = Asc("Y")
    Case 3
        KeyAscii = Asc("N")
    End Select
    End Sub3 用普通文本框,事后检查
    Private Sub Text1_Validate(Cancel As Boolean)
    If Mid(Text1, 3, 2) <> "YN" Or Not IsNumeric(Left(Text1, 2)) Or _
                    Not IsNumeric(Right(Text1, 2)) Then
    MsgBox "输入格式必须如11YN11,12YN11,67YN89等等"
    Cancel = True
    End If
    End Sub