-3

I have code for validating text_box which only accept alphabetic/lowercase characters. I have managed to add the code in the below code.

This is my code:

if (char.IsLetter(e.KeyChar) || e.KeyChar == 8)
{
    e.handled = false;
}
else
{
    e.handled = true;
}
  • http://stackoverflow.com/questions/8915151/c-sharp-validating-input-for-textbox-on-winforms – eddie_cat Sep 11 '14 at 18:13
  • Ok, you really need to go back and think through your post. I had a really hard time trying to clean this up, and it's still at a point where I don't understand what you want. – gunr2171 Sep 11 '14 at 18:18
  • Also, I removed your leading `{` and fixed the type on `IsLetter`. Always post code that compiles! – gunr2171 Sep 11 '14 at 18:18
  • You aren't asking a question. – Icemanind Sep 11 '14 at 18:19
  • @gunr2171 for your stress. `e.keychar` doesn't exist. `e.KeyChar` is the correct one :-). – Steve Sep 11 '14 at 18:21
  • @Steve, correct. I didn't know what the method this lives in was, so I didn't bother fixing that. – gunr2171 Sep 11 '14 at 18:22
  • sorry for that i just typed it so i know that too its case sensetive but i just wanted code for alphabet and i had asked that can i managed the code on that program or not if no than fine i will remove it but which code should i use then...and i told u that i am begineer in c# mistake happens by human being – Maharzan Manis Sep 11 '14 at 19:32

1 Answers1

0

Try the code below

public Form2()
{
    InitializeComponent();
    TextBox1.CharacterCasing = CharacterCasing.Lower;
}

private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
    e.Handled = !char.IsLetter(e.KeyChar);
}

Basically what I am doing here is

  1. In the constructor I am setting the textbox to convert any character typed to lower case
  2. Add a KeyPress event to the textbox and check the character typed is not a letter or character 8.
Mo Patel
  • 2,321
  • 4
  • 22
  • 37