SIGN UP MEMBER LOGIN:    
Resource

Time Validation in ASP.NET TextBox

VB Developer Resources Sep 06, 2009
This code snippet shows how to apply validation on an ASP.NET TextBox for time.
Option 1:

You can use a RegularExpressionValidator control.

Drag and drop a
RegularExpressionValidator control on your ASP.NET page next to the control you want to validate and set it's ControlToValidate property to the ID of the TextBox. 

Set
ValidateExpression property : ^([1-9]|1[0-2]|0[1-9]){1}(:[0-5][0-9][aApP][mM]){1}$

Option 2:

1. Make sure AutoPostBack property of TextBox is True.

2. Write this code on TextChanged event handler of the TextBox.

Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim t As DateTime
        If (DateTime.TryParse(TextBox1.Text, t) = True) Then
        Else
          ' Show your error message here.
           
TextBox1.Focus()
        End If

    End Sub


share this resource :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Sponsored by
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor