Check if string is numeric

Check if string is numeric
This is a one-line C# method that checks whether a string is a numerical value or not, by having regex (regular expressions) match a decimal with or without a floating point.
1. public static bool IsNumeric(string strToCheck)
2. {
3.     return Regex.IsMatch(strToCheck,"^\\d+(\\.\\d+)?$");
4. }

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top