12,815,986 members (39,870 online)
Rate this:
See more:
validation at codebehind C# allowed only numeric values & after decimal allowed only 2 digits and not allowed alpha numeric value in textbox
Posted 21-Mar-12 4:50am
ryanb31 21-Mar-12 9:53am

Are you asking a question? Have you tried using the built in Validator controls?

Rate this:

Rate this:

## Solution 4

put this in to your head scipt tag.
```var RegularExpression  =  new RegExp(^\d+(\.\d{1,2})?\$);
if (RegularExpression.match("your_number_string"))
{
} else
{
}
```
v2
Rate this:

## Solution 1

Use a RegEx or RegularExpressionValidator control
Rate this:

## Solution 2

try this

```public static bool IsDesimal(string strValue)
{
string decimalNumber = ".0123456789";
for (int i = 0; i < strValue.Trim().Length; i++)
{
if (decimalNumber.IndexOf(strValue[i]) == -1)
{
return false;
}
}

return true;
}

/// <summary>
/// Returns the Validate Input Numeric Value
/// </summary>
/// <param name="strValue"></param>
/// <returns>Numeric Value</returns>
public static bool IsNumeric(string strValue)
{
string decimalNumber = "0123456789";
for (int i = 0; i < strValue.Trim().Length; i++)
{
if (decimalNumber.IndexOf(strValue[i]) == -1)
{
return false;
}
}

return true;
}```
Mark Nischalke 21-Mar-12 13:06pm

A coding horror nominee
shreekar 21-Mar-12 15:52pm

This is a fail as it does not solve OP's problem. Besides, Regular expressions are the preferred way.
Rate this:

## Solution 3

You can find the RegEx expression for your requirement done in the link below.

http://gskinner.com/RegExr/?2rj2e[^]

Please try it and let me know if it works for you.

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

Top Experts
Last 24hrsThis month
 Jochen Arndt 215 Karthik Bangalore 204 Richard Deeming 185 Dave Kreskowiak 130 OriginalGriff 100
 OriginalGriff 4,427 Graeme_Grant 3,649 Karthik Bangalore 3,386 Jochen Arndt 2,391 ppolymorphe 2,287

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 21 Mar 2012