Monday 19 November 2012

How to validate the TextBox it takes Characters and Special symbols in C#.net

Some times in our project we have to validate the TextBox,so that The TextBox takes only Characters and Special Symbols in C#.net windows forms.for that i gave some code shown below.
code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Blogcode
{
    public partial class txtnumeric : Form
    {
        public txtnumeric()
        {
            InitializeComponent();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(char.IsNumber(e.KeyChar))
            {                                                      
                e.Handled=true;
            }

        }
    }
}

I hope this code will help you