Anatoly Lubarsky

Logo
MSSQL, .NET, Design. Life and Music

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

Related Posts:

Thursday, May 19, 2005 4:04 AM

If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish.

Post a Comment

Protected by CAPTCHAEnter the code you see
Name (*)  
E-mail (*)  
Url
Remember

Comment (*)