验证日期格式 [英] Validate the date format
本文介绍了验证日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在vb 2010中的表单中有一个文本框
,该文本框应仅接受日期,并且只能采用"yyyy/mm/dd"
I have a textbox
in my form in vb 2010 which should accept only dates and only in the format of "yyyy/mm/dd"
如何实现这一目标?请帮助
How to achieve this? Please help
推荐答案
Private Sub TextBox2_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles TextBox2.Validating
Dim test As Date
If Date.TryParseExact(TextBox2.Text.ToString(), "yyyy/mm/dd", _
System.Globalization.CultureInfo.CurrentCulture, _
Globalization.DateTimeStyles.None, test) Then
MessageBox.Show("Ok")
'TODO: ok
Else
e.Cancel = True
'TODO: not ok
End If
End Sub
这篇关于验证日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文