Question TextBox Question

raysefo

Well-known member
Joined
Jul 21, 2010
Messages
207
Programming Experience
Beginner
Hi,

I have a textbox and I would like to limit this textbox to enter 10 digits only. Is there a way to do it?

Best Regards
 
Use a regular TextBox and set MaxLength property, then validate that the content is digits only, or use a MaskedTextBox and set mask to ten digits.
 
You can achieve this by making use of the 'TextLength' property of the textbox control.
Ex:
VB.NET:
If TextBox1.TextLength > 10 Then
            'Inform the user or do something
        End If

Also, you can validate the test using 'IsNumeric'.
 
You can achieve this by making use of the 'TextLength' property of the textbox control.
Ex:
VB.NET:
If TextBox1.TextLength > 10 Then
            'Inform the user or do something
        End If

Also, you can validate the test using 'IsNumeric'.
Or much simpler, use the MaxLength property of the TextBox, and as for validating it you can simply use the Validating to return a Long.Tryparse(CType(sender, TextBox).Text, New Integer)
 
Back
Top