25 November 2008

C# Regex Number Validation With Regular Expression

In order to check whether an input is a valid number or not,
regular expressions
are very easy to use to validate the input value.

The sample function below show how to check if the input is number or not, code is in C#.

using System.Text.RegularExpressions;

public static bool IsItNumber(string inputvalue)
{
Regex isnumber = new Regex("[^0-9]");
return !isnumber.IsMatch(inputvalue);
}
IsItNumber("2"); will return true;
IsItNumber("A"); will return false;

Is number validation with regular expression in C#.

7 comments:

Note: Only a member of this blog may post a comment.