andrew4582

RegexPatterns

Jul 19th, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Core
  7. {
  8.     /// <summary>
  9.     /// This class contains several common regular expressions.
  10.     /// </summary>
  11.     public class RegexPatterns
  12.     {
  13.         /// <summary>
  14.         /// Alphabetic regex.
  15.         /// </summary>
  16.         public const string Alpha = @"^[a-zA-Z]*$";
  17.  
  18.  
  19.         /// <summary>
  20.         /// Uppercase Alphabetic regex.
  21.         /// </summary>
  22.         public const string AlphaUpperCase = @"^[A-Z]*$";
  23.  
  24.  
  25.         /// <summary>
  26.         /// Lowercase Alphabetic regex.
  27.         /// </summary>
  28.         public const string AlphaLowerCase = @"^[a-z]*$";
  29.  
  30.  
  31.         /// <summary>
  32.         /// Alphanumeric regex.
  33.         /// </summary>
  34.         public const string AlphaNumeric = @"^[a-zA-Z0-9]*$";
  35.  
  36.  
  37.         /// <summary>
  38.         /// Alphanumeric and space regex.
  39.         /// </summary>
  40.         public const string AlphaNumericSpace = @"^[a-zA-Z0-9 ]*$";
  41.  
  42.  
  43.         /// <summary>
  44.         /// Alphanumeric and space and dash regex.
  45.         /// </summary>
  46.         public const string AlphaNumericSpaceDash = @"^[a-zA-Z0-9 \-]*$";
  47.  
  48.  
  49.         /// <summary>
  50.         /// Alphanumeric plus space, dash and underscore regex.
  51.         /// </summary>
  52.         public const string AlphaNumericSpaceDashUnderscore = @"^[a-zA-Z0-9 \-_]*$";
  53.  
  54.  
  55.         /// <summary>
  56.         /// Alphaumieric plus space, dash, period and underscore regex.
  57.         /// </summary>
  58.         public const string AlphaNumericSpaceDashUnderscorePeriod = @"^[a-zA-Z0-9\. \-_]*$";
  59.  
  60.  
  61.         /// <summary>
  62.         /// Numeric regex.
  63.         /// </summary>
  64.         public const string Numeric = @"^\-?[0-9]*\.?[0-9]*$";
  65.  
  66.  
  67.         /// <summary>
  68.         /// Numeric regex.
  69.         /// </summary>
  70.         public const string Integer = @"^\-?[0-9]*$";
  71.  
  72.  
  73.         /// <summary>
  74.         /// Ssn regex.
  75.         /// </summary>
  76.         public const string SocialSecurity = @"\d{3}[-]?\d{2}[-]?\d{4}";
  77.  
  78.  
  79.         /// <summary>
  80.         /// E-mail regex.
  81.         /// </summary>
  82.         public const string Email = @"^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$";
  83.  
  84.  
  85.         /// <summary>
  86.         /// Url regex.
  87.         /// </summary>
  88.         public const string Url = @"^^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_=]*)?$";
  89.  
  90.  
  91.         /// <summary>
  92.         /// US zip code regex.
  93.         /// </summary>
  94.         public const string ZipCodeUS = @"\d{5}";
  95.  
  96.        
  97.         /// <summary>
  98.         /// US zip code with four digits regex.
  99.         /// </summary>
  100.         public const string ZipCodeUSWithFour = @"\d{5}[-]\d{4}";
  101.  
  102.  
  103.         /// <summary>
  104.         /// US zip code with optional four digits regex.
  105.         /// </summary>
  106.         public const string ZipCodeUSWithFourOptional = @"\d{5}([-]\d{4})?";
  107.  
  108.  
  109.         /// <summary>
  110.         /// US phone regex.
  111.         /// </summary>
  112.         public const string PhoneUS = @"\d{3}[-]?\d{3}[-]?\d{4}";
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment