arichexe
asked on
Regex for numeric check
The below only works if the number isn't negative or have decimals. How would I modify it to handle such?
if (Regex.IsMatch(MyString, @"^\d+$"))
Console.WriteLine(MyString + " is numeric");
if (Regex.IsMatch(MyString, @"^\d+$"))
Console.WriteLine(MyString
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ity", you probably just want to use a regular expression.
if (/\D/) { print "has nondigits\n" }
if (/^\d+$/) { print "is a whole number\n" }
if (/^-?\d+$/) { print "is an integer\n" }
if (/^[+-]?\d+$/) { print "is a +/- integer\n" }
if (/^-?\d+\.?\d*$/) { print "is a real number\n" }
if (/^-?(?:\d+(?:\.\d*)?|\.\d
if (/^([+-]?)(?=\d|\.\d)\d*(\
{ print "a C float\n" }