Sunday 18 November 2012

How to validate the TextBox it takes only Numerics and special charecters in C#.net windows applications

Some times in our Projects we need Validation for TextBox it takes only Numbers and special charecters for that i gave some RealTime dotnet snippet shown below snippet.
Code snipppet:
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.IsLetter(e.KeyChar))
            {
                e.Handled=true;
            }
        }
    }
}



    I hope this code will help you