We help IT Professionals succeed at work.

How to put validation in textbox in Vb.net windows form,

searchsanjaysharma
searchsanjaysharma used Ask the Experts™
on
I have textbox, iwant user to enter date in dd/mm/yyyy format. with ease as it us windows application.
Textbox name is tdd,tmm,tyy.
1.I want the focus should automatically jumb to tmm when tdd is entered and so on.
2.Person should be able to press number only.
3.if user missed something, the alert should come.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
well thats all in the programming
i mean you can set the tab order to go from one box to another ( see google) enter tab order vb or help in vs


you can set the mask in the properties box also to only get numbers

to only enter number you do this in you keypress
    Private Sub txtCENumber_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCENumber.KeyPress

        'celan out after first char digit entered
        If (Char.IsDigit(e.KeyChar)) Then
            If CleanAll = True Then
                ClearExcept = 3
                ClearAll_except_current_field()
                CleanAll = False
            End If
        End If
        If Not (Char.IsNumber(e.KeyChar) OrElse Char.IsControl(e.KeyChar) OrElse (AscW(e.KeyChar) = 8)) Then
            ' set CENumber textbox to accept only digits, the Backspace, the Tab, or the Enter key, nothing else
            e.Handled = True
            'ProcessSSN()

        ElseIf (AscW(e.KeyChar) = 13) OrElse (AscW(e.KeyChar) = 9) Then
            'The field's not empty and Enter was pressed.
            ' Set the focus to the Search button so the Leave property do its magic
            Me.txtTelePhone1.Focus()
        End If


    End Sub
alerts are set in you leave routine
ie like this
If Len(PhoneCheck) <> 10 Then
                ' it's not a valid phone.  Warn user and exit sub
                MessageBox.Show("The telephone entered, " & txtTelePhone1.Text & " is not a 10 digit number." & vbCrLf & "Please try again.", _
                     "Phone Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

Author

Commented:
ok