Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you set an input mask in .NET?

Status
Not open for further replies.

mbutch

Programmer
Nov 17, 2000
100
0
0
US
I can't find an input mask property for a text box object in .NET. I want to limit text box input to only four numbers.

Thanks
 
There is no mask control that ships with .NET.

You'll have to write one or buy one. Maybe download one, but I haven't seen any free ones so far that look any good.

Chip H.
 
If you have VB 6, you might be able to use its COM Masked Edit Control in your .Net app.
 
Yes, I was surprised that this functionality hasn't been provided. It's such a common need.
 
Is this just a case of limiting the number of characters input in the textbox ? Or are you specifically trying to prevent more than four numeric characters being entered ?
If the first is true can you not just set the 'MaxLength' (integer) property against the desired TextBox component ?
I'm hoping that I've not simply missed the point on this one. :)
Steve
 
I want to limit the field to numbers only.
 
Can you not just check the text as entered into the control as you exit it (validating it as such) ?
Alternatively could you not make use of the 'KeyPress' event and the 'KeyChar' to obtain the keyboard character that was pressed.
Steve
 
mbutch,

Check out the control I have written for this is VB.NET FAQs.

Craig
 
I tried out the code that SameerKhan pointed out (written by Jibin Pan) and it works quite well. It is easily modified & customized for specific needs and error handling.
---
dino
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top