Wednesday, June 8, 2011

How to Check string is Number or String

using System.Text.RegularExpressions;
 public bool IsNumeric(String strVal)
    {
        Regex reg = new Regex("[^0-9-]");
        Regex reg2 = new Regex("^-[0-9]+$|^[0-9]+$");
        return (!reg.IsMatch(strVal) && reg2.IsMatch(strVal));
    }

No comments:

Post a Comment