Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- textBox.KeyPress += new KeyPressEventHandler(textBox_KeyPress);
- private void textBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar < 65 || e.KeyChar > 122)
- {
- e.Handled = true;
- }
- }
- if (!Regex.IsMatch(textbox.Text, @"[a-zA-Z]"))
- {
- yourErrorProvider.setError(textbox, "Only A-Z accepted.");
- }
- if ((Convert.ToInt32(e.KeyChar) >= 65) && (Convert.ToInt32(e.KeyChar) <= 122))
- {
- errorProvider1.SetError(textBox1, "OK");
- errorProvider2.SetError(textBox1, "");
- }
- else
- {
- errorProvider2.SetError(textBox1, "Can not enter the numbers...");
- errorProvider1.SetError(textBox1, "");
- textBox1.Text = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement