Hi everyone
How can I put mask on win form text box so that it allows only numbers? And how it works for another masks data, phone zip etc.
I am using Visual Studio 2008 C#
Thanks.
Hi everyone
How can I put mask on win form text box so that it allows only numbers? And how it works for another masks data, phone zip etc.
I am using Visual Studio 2008 C#
Thanks.
You can use the MaskedTextBox control
http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx
Do you want to prevent input that isn't allowed or validate the input before it is possible to proceed?
The former could confuse users when they press keys but nothing happens. It is usually better to show their keypresses but display a warning that the input is currently invalid. It's probably also quite complicated to set up for masking an email-address regular expression for example.
Look at ErrorProvider to allow the user to type what they want but show warnings as they type.
For your first suggestion of a text box that only allows numbers, you might also want to consider a NumericUpDown.