i have a 1 textbox namely txtplate. I want the textbox that can input only Plate number. (example WXY 123 (with space and the 3 letters are in uppercase)

If you're using WinForms, you could use the MaskedTextBox control.

Alternately, if you are using WPF - You can download a toolkit that will allow you to create one using XAML.

The article for declaring it can be found here.

thank you sir but is there any other solutions? beside your suggestions?

These methods are the easiest.

The alternate way would be to capture each character inserted into the textbox, check it, then submit it.

You would have to set the size limit of the textbox also.

thank you sir but is there any other solutions? beside your suggestions?

What is it that you find unacceptable about the solutions proposed thus far?

you can use substring for that.... and make a condition

can you give some sample codes sir?

follow this step"

  1. create a masked textbox to your form
  2. then go to masked textbox property and find Mask
  3. select custom then type this LLL-999 (LLL means 3 letters only and 999 means 3 digits)
  4. run the program

you can check this link for more info.....
http://content.hccfl.edu/pollock/VB/Masking.htm

you want in your textbox first 3 letters(space)3 numbers?

First in your textbox Properties

CharacterCasing: Upper
MaxLength: 7

In your textbox Keypress event:

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

    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
    Private Sub killchar(ByVal e As System.Windows.Forms.KeyPressEventArgs)
        If Asc(e.KeyChar) < 97 Or Asc(e.KeyChar) > 90 And Asc(e.KeyChar) < 127 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

    Private Sub TextBox1_KeyPress(ByVal sender As 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)
            Call killchar(e)
        ElseIf TextBox1.Text.Length >= 3 Then
            Call NumberOnly(e)
            If Asc(e.KeyChar) = 32 Then
                e.Handled = False
            End If
        End If
    End Sub
commented: kljkljkljklj +3
commented: Looks like you just copy and pasted a (incorrect) solution someone had given you, without any thought or testing. It's very buggy. -1

First in your textbox Properties

CharacterCasing: Upper
MaxLength: 7

In your textbox Keypress event:

So what happens if the user moves the caret to some position other than the end of the text? And why are you allowing spaces everywhere?

can you please tell me sir where can i put the

Private Sub killchar(ByVal e As System.Windows.Forms.KeyPressEventArgs)
Private Sub LetterOnly(ByVal e As System.Windows.Forms.KeyPressEventArgs)
Private Sub NumberOnly(ByVal e As System.Windows.Forms.KeyPressEventArgs

im a newbie in vb.net :D thank you

can you please tell me sir where can i put the

Private Sub killchar(ByVal e As System.Windows.Forms.KeyPressEventArgs)
Private Sub LetterOnly(ByVal e As System.Windows.Forms.KeyPressEventArgs)
Private Sub NumberOnly(ByVal e As System.Windows.Forms.KeyPressEventArgs

im a newbie in vb.net :D thank you

I wouldn't put it anywhere if I were you; the code's incredibly buggy.

Why do all this extra coding? Masked textbox has it all built in...

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.