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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.