Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time validation in maskedTextbox

Status
Not open for further replies.

ZmrAbdulla

Technical User
Apr 22, 2003
4,364
AE
How can I validate input of maskedtextbox with time value?
masking style is __:__

I need to use Military Time (24hr format)


________________________________________________________
Zameer Abdulla
Help to find Missing people
 
in the mask property

"HH:mm"

is for military time

the other is

"hh:mm"

the MM like in "dd/MM/yyyy" is used for months

to get the __ you need to set _ as the promptchar

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
I created the InputMask from the dialog box. That was set to Time(European/Military)"00:00" and shows like __:__

My problem is user shouldn't enter a time value other than 24hr time format. He can enter 65:45 or something like that.

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
are you using vb2005?

setting the mask to 00:00 won't work since that will allow everything from 0 to 9.

Christiaan Baes
Belgium

My Blog
"In a system where you can define a factor as part of a third factor, you need another layer to check the main layer in case the second layer is not the base unit." - jrbarnett
 
Yes it is vb2005. This mask was prompted to me by the dialog.


Ok found it
Code:
    Private Sub frmMaster_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        Me.MaskedTextBox1.Mask = "00:00"
        Me.MaskedTextBox1.ValidatingType = GetType(System.DateTime)
        Me.ToolTip1.IsBalloon = True
       
    End Sub
Code:
    Private Sub MaskedTextBox1_TypeValidationCompleted(ByVal sender As Object, ByVal e As TypeValidationEventArgs) Handles MaskedTextBox1.TypeValidationCompleted

        If Not IsDate(Me.MaskedTextBox1.Text) = True Then
            Me.ToolTip1.ToolTipTitle = "Invalid Time"
            Me.ToolTip1.Show("The data you supplied must be a valid time in the format between 00:00 to 23:59", Me.MaskedTextBox1, 0, -20, 1000)
        End If

    End Sub

________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top