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;
}


Comments

Author: Manindra Kumar Upadhyay09 Apr 2010 Member Level: Gold   Points : 1

try this link:
http://www.manindra.net/post/2010/04/09/AspNet-Regular-Expressions.aspx



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: