Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I validate user entered string in textbox?
I mean it should be alphabetic characters only, if anybody enter digits or punctuation symbols it should not be accepted in that textbox.
Posted
Updated 20-Apr-10 22:01pm
v2

Use a Masked Text box[^] and set the mask to only upper and lower A-Z
 
Share this answer
 
Now TextBox in Windows application of C# have something called as events
all u have to do is use the KeyPress event of the textbox and paste in the following code...

C#
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            //only numbers code

            if (char.IsNumber(e.KeyChar) == false)
            {
                e.Handled = true;
            }
            //backspace workin keycode
            if (e.KeyChar == (char)Keys.Back)
            {
                e.Handled = false;
            }
            //if u want that alphabets must be entered then just use
           // char.IsLower in place of char.IsNumber
        }


and ur done...

Do rate my answer once u find it useful

Thanks & Regards
Radix :rose:
 
Share this answer
 
for this kind of issue i have created a one article

just check below link you will get answer to your question
Enhanced Textbox Control
 
Share this answer
 
HI,

you use the Following code on windows application.
Only accept Numbers.

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{ //only numbers code
if (char.IsNumber(e.KeyChar) == false) {
e.Handled = true;
}
//backspace workin keycode
if (e.KeyChar == (char)Keys.Back)
{
e.Handled = false;
}
//if u want that alphabets must be entered then just use
// char.IsLower in place of char.IsNumber
}
 
Share this answer
 
Comments
[no name] 9-Nov-12 4:57am    
thaks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900