Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
Sheshu
Posted 30-Jan-13 21:18pm
Comments
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....
Rate this: bad
good
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[^]
 
Cheers,
Edo
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

use javascript fuction to check it onBlur event
  Permalink  
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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;
            }
            else
            {
                MessageBox.Show("Only Character");
                e.Handled = true;
            }
 
Surely this will work try it....
  Permalink  
Rate this: bad
good
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">
 

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>
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 210
3 Afzaal Ahmad Zeeshan 204
4 CPallini 185
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
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