A normal query asked is to validate the date in a specific format. The sample code demonstrates to validate a date in a specific given format. Sample Below checks for the date given in mm/dd/yy or mm/dd/yyyy format.
The Namspace used in the demonstration is System.Globalization
Step 1: main.aspx
<asp:Button id="btnValidate" runat="server" Text="Validate Date"></asp:Button>
<asp:Label id="Label1" runat="server">Enter Date</asp:Label>
<asp:TextBox id="txtDate" runat="server"></asp:TextBox>
Step 2: main.aspx.
vb
Private Sub btnValidate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidate.Click
Try
Dim myDateTimeUS As System.DateTime
Dim format As New System.Globalization.CultureInfo("en-US", True)
myDateTimeUS = System.DateTime.Parse(txtDate.Text, format)
Response.Write("Valid Date")
Catch ex As Exception
Response.Write(ex.Message)
Response.Write("Not Valid Date")
End Try
(not tested)
Yippie Ki Yea, Mr. Falcon.