我有一个文本框,如何判断里面的内容是不是YYYY-MM-DD-B形式的啊?(如:2005-01-01-b),最后一位是b或是z或是y

解决方案 »

  1.   

    首先判断长度,用len
    再判断_符号.
      

  2.   

    用SPLIT函数按照"-"把内容分割到字符串数组,再依次判断
      

  3.   

    判断比较麻烦
    按楼上两位的还得判断年月日必须是数字最后一位是字母b、z、y
      

  4.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim Arr() As String
        Dim i As Long
        Dim MyDate As Date
        Arr = Split(Text1.Text, "-")
        If UBound(Arr) < 1 Then Exit Sub
        MyDate = Format(Arr(0) & "-" & Arr(1) & "-" & Arr(2), "yyyy-mm-dd")
        Debug.Print MyDate
        Debug.Print Arr(UBound(Arr))
    End SubPrivate Sub Form_Load()
        Text1.Text = Date & "-z"
    End Sub
      

  5.   

    正则表达式的介绍
    http://www.soulogic.com/doc/RegularExpressions/
      

  6.   

    用SPLIT函数按照"-"把内容分割到字符串数组,再依次判断
      

  7.   

    Private Sub Text1_LostFocus()
    If Len(Text1.Text) > 12 Then
      MsgBox "错误!"
      Text1.SetFocus
      Text1.Text = ""
      Exit Sub
    ElseIf Len(Text1.Text) <= 12 Then
      If Right(Text1.Text, 2) <> "-z" And Right(Text1.Text, 2) <> "-b" And Right(Text1.Text, 2) <> "-y" Then
        MsgBox "错误!"
        Text1.SetFocus
        Text1.Text = ""
        Exit Sub
      ElseIf IsDate(Left(Text1.Text, 10)) = False Then
        MsgBox "错误!"
        Text1.SetFocus
        Text1.Text = ""
        Exit Sub
      End If
    End If