Some Validators

Hopefully, these might help you as well. There were times when I could not come up right away with them.

 

public static class RegexValidationExpression
{ 
public const string PhoneNumber = @"^(\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4}))*$";
public const string AnyPositiveInteger = @"^[0-9]*$";
public const string AlphabeticalCharactersNoSpace = @"^[a-zA-Z]*$";
public const string ZipCodeUseOnly = @"^(\d{5}-\d{4}|\d{5}|\d{9})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)*$";
public const string ZipCodeRequiredUseOnly = @"^(\d{5}-\d{4}|\d{5}|\d{9})$|^([a-zA-Z]\d[a-zA-Z] \d[a-zA-Z]\d)+$";
public const string ValidStringWithSpace = @"^[a-zA-Z' ']+$";
public const string AlphaNumeric = @"^[a-zA-Z0-9]+$";
public const string EmailAddress = @"^([a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z](?:[a-zA-Z-]*[a-zA-Z])?\.)+[a-zA-Z]{3})+$";
public const string WebsiteAddress = @"^(((http|https)\:\/\/)?[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?)?$";
public const string OptionalEmailAddress = @"^([a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z](?:[a-zA-Z-]*[a-zA-Z])?\.)+[a-zA-Z]{3})*$";
public const string NullableValidStringWithSpecialCharacters = @"^([a-zA-Z' '.!#$%&'*+/=?^_`{|}~-])*$";
public const string AmountValidator = @"^((\d{0,8})|(\d{0,8}[.]\d{1,2}))$";
public const string NumberLengthValidator = @"^(\d{10})+$";
public const string RequiredPhoneNumber = @"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$";
public const string Suffix = @"^[a-zA-Z0-9' ']*$";
public const string Year = @"^([0-9]{4})?$";
public const string AlphaNumericOptional = @"^[a-zA-Z0-9]*$";
public const string AlphaNumericOptionalWithSpace = @"^[a-zA-Z0-9' ']*$";
public const string NumberRangeValidator = @"^[0-9]*$";
public const string OptionalValidStringWithSpace = @"^[a-zA-Z' ']*$";
public const string LocationValidator = @"^[a-zA-Z0-9' ']*$";
public const string Weight = @"^(?!000)([0-9])*$";
public const string EmployerName = @"^([a-zA-Z\d' \/\,\.\-#&']*[\.]*)*$";

}

 

Add comment