Friday, February 10, 2012

Business Validation Helper

Sometimes in  server side we need to validate the incoming request. Here is few of

public static bool IsNumeric(string numeric)
       {
           return !(Regex.IsMatch(numeric, @"[^\d]"));
       }

 public bool IsAlphaNumeric(string alphaNumeric)
       {
           alphaNumeric = alphaNumeric.Trim();
           alphaNumeric = StripCarriageReturn(alphaNumeric);
           return !(Regex.IsMatch(alphaNumeric, @"[^\w]"));
       }
  public static bool IsDate(string date, string date_format)
       {
           try
           {
               DateTime.ParseExact(date, date_format, DateTimeFormatInfo.InvariantInfo);
           }
           catch
           {
               return false;
           }
           return true;
       }

No comments:

Post a Comment