C# Text Box Validation - Conount-blogger tips,Marketing, Web Design, Computer Hardware and Network, Business and Finance.

C# Text Box Validation




Today we will see how to make a textbox that only accepts numbers or only characters in C#.Use this Validation in TextBox KeyPress Event.




After applying this below code .you can type only words in the Text box. you can't type Numbers and Other symbols in that Text box

            if(!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar))

            {

                e.Handled = true;

            }

           
After applying this below code .you can type only Numbers in the Textbox. you can't type Words and Other symbols in that textbox

            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))

            {

                e.Handled = true;

            }
       

After applying this below code .you can type  Numbers and Words in the Textbox. you can't type Other symbols in that textbox.
 
            // allow digit + char + white space

            if (!char.IsControl(e.KeyChar) && !char.IsLetterOrDigit(e.KeyChar) && !char.IsWhiteSpace(e.KeyChar))

            {

                e.Handled = true;

            }

        

If you Like Our articles Don't Forget To Share and Comment your Ideas !!!


EmoticonEmoticon

Message From Conount
If you fell down yesterday, stand up today.
Ok