0

I was trying to get this work, but couldn't find a way to work this out. I'm new to vb.net. In a text box, the user enters a number for example a 9 digit number. I want the user enter to enter a 9 digit number that is starting from 8. if the very first number of that set is not starting with 8 then give a error msg to the user to enter a number starting from 8.

How do i get this work on vb.net =S

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by codeorder
0

See if this helps.

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If TextBox1.TextLength = 0 Then '// check if TextBox is empty.
            If Not e.KeyChar = "8" Then '// if not "8".
                e.Handled = True '// cancel the key pressed.
                MsgBox("First character is not 8.", MsgBoxStyle.Critical) '// display message.
            End If
        End If
    End Sub
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.