12,290,522 members (56,327 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 3:50am
ryanb31 21-Mar-12 9:53am

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

Rate this:

## Solution 5

One alternative to validations is a masked text box. You can find some for ASP.NET as well.

http://www.asp.net/community/control-gallery/Item.aspx?i=387[^].

For the pure JavaScript solution with jQuery, please see this discussion:

A couple of jQuery plug-ins you can try:

—SA
Rate this:

## Solution 4

```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.

Top Experts
Last 24hrsThis month
 KARTHIK Bangalore 445 OriginalGriff 389 ppolymorphe 225 F-ES Sitecore 170 Dave Kreskowiak 161
 OriginalGriff 8,095 ppolymorphe 4,987 CHill60 4,900 KARTHIK Bangalore 4,317 Sergey Alexandrovich Kryukov 4,153