Regular Expressions

A few common Regex patterns I often use…

                case ExpressionType.PositiveIntegers:
                    return @"^\d{1,9}$";
                case ExpressionType.Numbers:
                    return @"(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)";
                case ExpressionType.PositiveNumbers:
                    return @"(^\d\d*\.\d*$)|(^\d\d*$)|(^\.\d\d*$)";
                case ExpressionType.EmailAddress:
                    return @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$";
                case ExpressionType.FirstName:
                    return @"^[A-Za-z\-']{1,50}$";
                case ExpressionType.Password:
                    return @"^[A-Za-z0-9\!\?\%\&\*\^_\-\+\=\#\~\@\£\$\(\)\[\]\{\}\:\;\/\\'\x22]{6,20}$";
                case ExpressionType.Postcode:
                    return @"^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][ABDEFGHJLNPQRSTUWXYZabdefghjlnpqrstuwxyz]{2}$";
                case ExpressionType.CreditCardNumber:
                    return @"^((\d{16})|(\d{15})|(\d{18}))$";
                case ExpressionType.CCVNumber:
                    return @"^(\d{4})|(\d{3})$";
                case ExpressionType.IssueNumber:
                    return @"^(\d{1})$";
                case ExpressionType.HTMLTags:
                    return @"<(.|\n)*?>";
                case ExpressionType.HTMLTagsNotBR:
                    return @"(\<)(?!br(\s|\/|\>))(.*?\>)";
                case ExpressionType.Title:
                    return @"^((Mr)|(Mrs)|(Miss)|(Ms)|(Dr)|(Sir))$";
  1. No comments yet.
(will not be published)