Here's my code:
private void Form1_Load(object sender, EventArgs e)
{
maskedTextBox1.Mask = "*[L]";
maskedTextBox1.MaskInputRejected += new MaskInputRejectedEventHandler(maskedTextBox1_MaskInputRejected);
}
How can I set it to accept only letters, but however many the user wants? Thanks!
If you want only letters to be entered you can use this in keyPress event
This would be easy if masked text boxes accepted regular expression, but unfortunately they don't.
One (albeit not very pretty) way you could do it is to use the optional letter
?
mask and put in the same amount as the maximum length you'll allow in the text box, i.eAlternatively you could use your own validation instead of a mask and use a regular expression like so
Or yet another way would be to ignore any key presses other than those from letters by handling the KeyPress event, which in my opinion would be the best way to go.