I have a textbox has a maxlength of 18, e.g Textbox=ABC123456789012345
i want that the first 3 input must be letters only.

Ok its fun solving it. anyways heres the code :)


'Subroutine for Letteronly
Private Sub LetterOnly(ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If Asc(e.KeyChar) < 65 Or Asc(e.KeyChar) > 90 And Asc(e.KeyChar) < 97 And Asc(e.KeyChar) > 122 Then
            If (Asc(e.KeyChar) <> 32) Then
                e.Handled = True
            End If
        End If

        If Asc(e.KeyChar) = 8 Then
            e.Handled = False
        End If

    End Sub

'Subroutine for Numberonly
Private Sub NumberOnly(ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
            e.Handled = True
        End If

        If Asc(e.KeyChar) = 8 Then
            e.Handled = False
        End If

 End Sub

 'Do the trick
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

        If TextBox1.Text.Length >= 0 And TextBox1.Text.Length < 3 Then
            Call LetterOnly(e)
        ElseIf TextBox1.Text.Length >= 3 Then
            Call NumberOnly(e)
        End If

        If TextBox1.Text.Length = 17 Then
            TextBox1.Enabled = False
        End If

    End Sub
commented: Don't hand out full solutions, the OP should be doing their own work. The code's very buggy anyways. -1

thanks bro.. i solved my problem.. Godbless :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.