Check if String is Integer Using Regular Expression
In .NET 2.0 there is a TryParse method for Int32. However TryParse is not compatible with .NET 1.1. The solution below is compatible with .NET 1.1 and demonstrates how to check if string is integer, using one simple regular expression.
public bool IsNumeric(string inputData)
{
Regex isNumber = new Regex(@"^\d+$");
Match m = isNumber.Match(inputData);
return m.Success;
}
public bool IsNumeric(string inputData)
{
Regex isNumber = new Regex(@"^\d+$");
Match m = isNumber.Match(inputData);
return m.Success;
}
Labels: Regular Expression

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home