Wednesday, May 11, 2011

Useful Utility Functions

using System.Text.RegularExpressions;

public static bool IsNumeric(string sValue)
        {
            if (sValue.Trim() == "")
                return false;
            else
                return Regex.Match(sValue, "(-{0,1}[0-9]+){0,1}(file://.%7b0,1%7d[0-9]+)%22).value/ == sValue;
        }
        public static bool IsWholeNumeric(string sValue)
        {
            if (sValue.Trim() == "")
                return false;
            else
                return Regex.Match(sValue, "(-{0,1}[0-9]+)").Value == sValue;
        }
 public static bool IsValidSSN(string sValue)
        {
            if (sValue.Trim().Length == 0)
                return false;
            else
                return (Regex.Match(sValue, @"^\(\d{3}\)-\d{2}-\d{4}$").Success || Regex.Match(sValue, @"^\d{3}-\d{2}-\d{4}$").Success);
        }
public static bool IsDecimalNumeric(string sValue)
        {
            if (sValue.Trim() == "")
                return false;
            else
                return Regex.Match(sValue, "(-{0,1}[0-9]+){0,1}(.{0,1}[0-9]+)").Value == sValue;
        }
        public static bool IsValidEmail(string sValue)
        {           
            if (sValue.Trim().Length == 0)
                return false;
            else
                return Regex.Match(sValue, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$").Value == sValue;
        }
 public static bool IsValidPhoneNumber(string sValue)
        {
            if (sValue.Trim().Length == 0)
                return false;
            else
                return (Regex.Match(sValue, @"^\(\d{3}\) \d{3}-\d{4}").Success || Regex.Match(sValue, @"^\d{3}\d{3}-\d{4}").Success);
        }

No comments:

Post a Comment