Mega Code Archive

 
Categories / C# / Regular Expressions
 

Use Regular expression to check if a string is a number

using System; using System.IO; using System.Text.RegularExpressions; public sealed class Utils {     public static bool IsNumeric(string input)     {         Regex r = new Regex(@"^-?[0-9]{1,}\.?[0-9]{0,}$");         if (r.Match(input).Success)             return true;         else             return false;     } }