Click here to Skip to main content
13,553,262 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi friends,

In my application having morethan 5 textboxes .In this textbox i want to put one validate control whenever enter in Name textboxes in values it automatically show error message like please enter alphabets.
Problem: only Accept alphabets does nt accepts in Numbers .please help me.........

Thanks in Advance
Posted 30-Jan-13 20:18pm
Balamurugan1989 31-Jan-13 4:18am
R u working in windows or web???
kayalasheshu 31-Jan-13 4:25am
web but i need both if u knw......
Balamurugan1989 31-Jan-13 4:41am
If it works for u accept my solution...
Balamurugan1989 31-Jan-13 4:31am
For windows i have updated the answer below it will useful for u...
kayalasheshu 31-Jan-13 6:45am
i need c# code not in VB
Balamurugan1989 31-Jan-13 7:26am
Its C# only....
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi kayalasheshu,

Lucky for you, MS has an off-the-shelf validator controls.

See this[^] article doing a nice validator controls review.

You can out this nice CodeProject article[^]

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

use javascript fuction to check it onBlur event
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

You will find this useful.

A Tiny Javascript Framework for Common Validation Scenarios.[^]

although this link is currently disallowing the input, you can change it to show errors too.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

If you are working in Windows application follow the below steps it will work,
1.Right Click Textbox
2.Go to Properties
3.Click the Event image in the properties window.
4.Double Click KeyPress in the textbox.
5.It will pass to Code Page,in the code page u need to write the below coding
if ((e.KeyChar >= 65 && e.KeyChar <= 90) || (e.KeyChar >= 97 && e.KeyChar <= 122) || e.KeyChar == 32 || e.KeyChar == 8)
                e.Handled = false;
                MessageBox.Show("Only Character");
                e.Handled = true;

Surely this will work try it....
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

if you use web based then use below function

public bool IsAlpha(string input)
    return Regex.IsMatch(input, "^[a-zA-Z]+$");
public bool IsAlphaNumeric(string input)
    return Regex.IsMatch(input, "^[a-zA-Z0-9]+$");

public bool IsAlphaNumericWithUnderscore(string input)
    return Regex.IsMatch(input, "^[a-zA-Z0-9_]+$");

or if you use Web development then use java script

script type="text/javascript" language="javascript">
    function validateNumbersOnly(e) {
        var unicode = e.charCode ? e.charCode : e.keyCode;
        if ((unicode == 8) || (unicode == 9) || (unicode > 47 && unicode < 58)) {

            return true;


        else {

            window.alert("This field accepts only Numbers");

            return false;




on page use below code
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" Display="None" ErrorMessage="Accepts only numbers." ControlToValidate="TextBox1" ValidationExpression=""^[0-9]*$" Text="*"></asp:RegularExpressionValidator>

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03-2016 | 2.8.180515.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100