Click here to Skip to main content
11,496,146 members (346 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
See more: C#
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 21:18pm
Balamurugan1989 at 31-Jan-13 4:18am
R u working in windows or web???
kayalasheshu at 31-Jan-13 4:25am
web but i need both if u knw......
Balamurugan1989 at 31-Jan-13 4:41am
If it works for u accept my solution...
Balamurugan1989 at 31-Jan-13 4:31am
For windows i have updated the answer below it will useful for u...
kayalasheshu at 31-Jan-13 6:45am
i need c# code not in VB
Balamurugan1989 at 31-Jan-13 7:26am
Its C# only....
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[^]

use javascript fuction to check it onBlur event
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.
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....
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">

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
0 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2015
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