h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Business Validation Via Regular Expression in C#.Net

public static bool BOValidation(Validate mode, TextBox input)
{
switch (mode)
{
case Validate.EmailValidation:
_pattern = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.TimeValidation:
_pattern = @"^(20|21|22|23|[01]\d|\d)(([:][0-5]\d){1,2})$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.AlphabetValidate:
_pattern = @"^[a-zA-Z]*$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.AlphabetSpaceDotValidate:
_pattern = @"^[a-zA-Z\s\.]*$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.AlphaNumericCommaSpaceHyphenUnderscoreValidate:
_pattern = @"^[a-zA-Z0-9\s,-_&]*$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.DecimalValidate:
_pattern = @"^[-+]?\d+(\.\d+)?$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.NumberValidate:
_pattern = @"^[0-9]*$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.PhoneNumberValidate:
_pattern = @"^[-+\s]?[0-9\s,()-]*$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.PostalCodeValidate:
_pattern = @"^[-+]?[0-9]*$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.UserNameValidate:
_pattern = @"^[a-zA-Z0-9_]*$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.FTPFilePathValidation:
_pattern = @"^([a-zA-Z0-9])*/[a-zA-Z0-9]+)$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.URLValidate:
_pattern = @"^((https?|ftp|news):\/\/)?www\.([a-z]([a-z0-9\-]*)+\.
(aero|arpa|asia|biz|cat|com|coop|edu|gov|info|int|jobs|lan|mil|mobi|museum|nato|name|net|org|pro|store|tel|travel|web|[a-z]{2}|[a-z]{2}\.[a-z]{2}))$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.FilePathValidate:
_pattern = @"([a-zA-Z]:(\\w+)*\\[a-zA-Z0_9]+)?.doc|.docx |.pdf";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
case Validate.PercentageValidation:
_pattern = @"^(100(?:\.0{1,2})?|0*?\.\d{1,2}|\d{1,2}(?:\.\d{1,2})?)$";
_match = Regex.Match(input.Text.Trim(), _pattern, RegexOptions.IgnoreCase);
break;
}
return _match.Success;
}