Click here to Skip to main content
15,886,101 members
Articles / Web Development / ASP.NET / ASP.NET2.0

to validate for numbers and alphabets in c# asp.net2.0 in codebehind file

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
28 Dec 2012CPOL 0  
Hi,Try this:bool includesNotOnlyNumeric = Regex.IsMatch(textBox.Text, @"\D");if (includesNotOnlyNumeric){ // don't show an alert box}else{ // show an alert box}

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
28 Dec 2012OriginalGriff
You could use a Regex: string str = myTextBox.Text; Regex includesNonNumeric = new Regex(@"[^\d]"); if (includesNonNumeric.IsMatch(str)) { // OK } else { //...
Please Sign up or sign in to vote.
28 Dec 2012nityasri 2 alternatives  
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...

License

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


Written By
Student
Europe Europe
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions