vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Monday, June 13, 2011

How to Validate Data and time in Vb.net



Hi..
I need an requirement to validate Data and time in textbox, then i goggled but i didn’t get any easiest way to validate data and time. Lastly i found this method to validate
date and time in vb.net.i hope this type definitely helpful to you...Even if you know any easiest methods then this one. please post your comments and code. 


Time:
 
Dim Datechk,tich as Boolean
GetValiddate(textbox1.text)


                        If datechk = False Then
                            MsgBox("Enter correct Date Format", MsgBoxStyle.Information)
                           End If


GetValidtime(textbox1.text)


                        If tich = False Then
                            MsgBox("Enter correct Time Format", MsgBoxStyle.Information)
                           End If




  Sub GetValidTime(ByVal atimestring As String)


        Try
            Dim dt As DateTime = DateTime.ParseExact(atimestring, "HH:mm:ss", Nothing)
            tich = True
        Catch
            tich = False
        End Try
    End Sub


Date:


 Sub GetValiddate(ByVal datetring As String)


        Try
            Dim dt As DateTime = DateTime.ParseExact(datetring, "dd/MM/yyyy", Nothing)
            datechk = True
        Catch
            datechk = False
        End Try
    End Sub

Another Method for Checking Date :

                        datechk = IsDate(textbox1.text) 'It return Boolean Value.

Even if you know any easiest methods then this Code.please post your comments and code.

0 comments:

Post a Comment