vb 检测text的输入格式
来源:百度知道 编辑:UC知道 时间:2024/06/02 23:52:22
当光标移出文本框的时候进行判断即可,非常简单,给你代码:
Private Sub Text1_LostFocus()
If IsDate(Text1.Text) = False Then
MsgBox "内容不是日期型数据,请重新输入"
Text1.SetFocus
Text1.Text = ""
End If
End Sub
dim ? data
可以用正则表达式··我最近在研究中呢~~我是用vb.net的~~
Private Sub txtnotedate1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii = 8) Then
txtnoteerror2.Visible = True
txtnoteerror2.Caption = "日期只能输入数字!"
txtnotedate1.Text = ""
KeyAscii = 8
Else
txtnoteerror2.Visible = False
End If
If Len(txtnotedate1.Text) = 4 Then
txtnotedate1.Text = txtnotedate1.Text & "-"
txtnotedate1.SelStart = Len(txtnotedate1.Text)
If KeyAscii = 8 Then
txtnotedate1 = ""
End If
ElseIf Len(txtnotedate1.Text) = 7 Then
txtnotedate1.Text = txtnotedate1.Text & "-"
txtnotedate1.SelStart = Len(txtno