Max characters in textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Alkis Arxontas
    New Member
    • Mar 2011
    • 10

    Max characters in textbox

    Is there a way to make the textbox stop typing when a user types numbers? I don't want an error message, I'd just like the user to be able to insert 10 numbers and then it shouldn't add any newly typed numbers.
    The code I have so far is

    Private Sub TextBox1_KeyPre ss(ByVal sender As Object, ByVal e As System.Windows. Forms.KeyPressE ventArgs) Handles TextBox1.KeyPre ss
    If Not IsNumeric(e.Key Char) Then
    MessageBox.Show ("Please insert numbers only.", "Error!", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
    e.KeyChar = Nothing
    End If
    End Sub
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    #2
    Hi,

    Use the MaxLength Property of TextBox. By Setting it to 10, You can achieve the mentioned one.

    Regards
    Vijay.R

    Comment

    Working...