ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

IsNumeric

Checks if a string value is numeric according to you system culture.

Source

public static bool IsNumeric(this string theValue)
{
    long retNum;
    return long.TryParse(theValue, System.Globalization.NumberStyles.Integer, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
}

Example

string value = "abc";
bool isnumeric = value.IsNumeric();// Will return false;
value = "11";
isnumeric = value.IsNumeric();// Will return true;

Author: Faisal Iqbal

Submitted on: 1 apr. 2009

Language: C#

Type: System.String

Views: 15915