Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
to validate for numbers and alphabets in c# asp.net2.0 in codebehind file,the textbox should accept all numbers,alphabets,special characters...but textbox should not contain only numbers if it contains only numbers error message in alert box should be thrown..please help me how to code in c#.net in code behind file
Posted

Hi,

Try this:
C#
bool includesNotOnlyNumeric = Regex.IsMatch(textBox.Text, @"\D");
if (includesNotOnlyNumeric)
{
    // don't show an alert box
}
else
{
    // show an alert box
}
 
Share this answer
 
v2
Comments
__TR__ 29-Dec-12 5:16am    
5ed!
Thomas Daniels 29-Dec-12 5:33am    
Thank you!
You could use a Regex:
C#
string str = myTextBox.Text;
Regex includesNonNumeric = new Regex(@"[^\d]");
if (includesNonNumeric.IsMatch(str))
    {
    // OK
    }
else
    {
    // Failed
    }
 
Share this answer
 
Comments
nityasri 29-Dec-12 3:53am    
what namespace we have to use here sir?
OriginalGriff 29-Dec-12 4:01am    
Try adding:
using System.Text.RegularExpressions;
nityasri 29-Dec-12 4:02am    
thank u griff
OriginalGriff 29-Dec-12 4:45am    
You're welcome!
nityasri 29-Dec-12 4:05am    
thanks a lot yaar...problem solved:)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900