Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Simple Code For Date Validation In Vb.Net
Author:
Ranjan D
E-mail:
Click to e-mail author
Submitted:
8/31/2006
Version:
VB.NET 2003
Compatibility:
VB.NET 2003, VB.NET 2005
Category:
Date/Time
Views:
101134
A Very simple code for date validation in vb.net. The date formate to be given is dd/mm/yyyy.
Declarations:
'none
Code:
' Validation for Number Function NumCheck(ByVal str As String) Dim good As String = "0123456789" Dim i As Integer For i = 0 To str.Length - 1 Step 1 If good.IndexOf(str.Chars(i)) = True Then Return False End If Next Return True End Function Function datevalidate(ByVal pres_date As String) Dim s As String Dim splited_date(3) As String Dim date_pre As String Dim month As String Dim year As String If (Len(Trim(pres_date))) = 0 Or pres_date.Length > 10 Then Return False 'Display_Error(db.Fetch_Error_Description(7)) Exit Function Else Dim pos As Integer pos = InStr(1, Trim(pres_date), "/") If InStr(pos + 1, Trim(pres_date), "/") <> 0 Then Try s = Trim(pres_date) splited_date = s.Split("/") date_pre = splited_date(0) month = splited_date(1) year = splited_date(2) If NumCheck(date_pre) = False Then Return False End If If NumCheck(month) = False Then Return False End If If NumCheck(year) = False Then Return False End If Dim d As New Date(Right(s, 4), Mid(s, 4, 2), Left(s, 2)) If d > Today() Then pres_date = "" Return False 'Display_Error(db.Fetch_Error_Description(7)) Exit Function End If Catch ex As Exception pres_date = "" Return False Exit Function 'Display_Error(db.Fetch_Error_Description(7)) End Try Else pres_date = "" Return False Exit Function 'Display_Error(db.Fetch_Error_Description(7)) End If End If Return True End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement