General Regular Expression Class

This is a regular expression class for handling most of the validation. I have created this for my project use. All general validations like check for emails, empty, isnumeric have been included in this Class.

A Small Snippet from the Class is here for your reference...

public static bool IsNumber(string str)
Regex objNotNumberPattern = new Regex("[^0-9.-]");
Regex objTwoDotPattern = new Regex("[0-9]*[.][0-9]*[.][0-9]*");
Regex objTwoMinusPattern = new Regex("[0-9]*[-][0-9]*[-][0-9]*");
String strValidRealPattern = "^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$";
String strValidIntegerPattern = "^([-]|[0-9])[0-9]*$";
Regex objNumberPattern = new Regex("(" + strValidRealPattern + ")|(" + strValidIntegerPattern + ")");

return !objNotNumberPattern.IsMatch(str) &&
!objTwoDotPattern.IsMatch(str) &&
!objTwoMinusPattern.IsMatch(str) &&

public static bool IsValidEmail(string email)
//regular expression pattern for valid email
//addresses, allows for the following domains:
string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.
//Regular expression object
Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);
//boolean variable to return to calling method
bool valid = false;

//make sure an email address was provided
if (string.IsNullOrEmpty(email))
valid = false;
//use IsMatch to validate the address
valid = check.IsMatch(email);
//return the value to the calling method
return valid;

For whole class you can download the attachment...


  • Validation Class (27874-23120-Validation.cs.txt)
  • Comments

    Author: Manindra Kumar Upadhyay09 Apr 2010 Member Level: Gold   Points : 1

    try this link:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: