I tried several things, could not get it to work. I need to exclude PO Boxes. I thought I just had to wrap it?! .. but it doesn't work. Any thoughts?
^((?i)[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]\s*(\d.))*$
EDIT: Sorry, this is what I'm looking for.
Example: when entering "PO BOX" or "Post Office", I need regex to be false. When the input is 7821 Test street, I need the regular expression to be true.
I am trying to use it in an ASP.net MVC project
/// <summary> /// Regex for street fields /// </summary> [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] public class StreetAddressAttribute : RegularExpressionAttribute, IClientValidatable { /// <summary> /// Regular expression validation for street field /// </summary> public StreetAddressAttribute() : base(@"^(?!(?i)[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]\s*(\d.)*)$") { } /// <summary> /// Client side validation /// </summary> /// <param name="metadata">Modelmetadata</param> /// <param name="context">ControllerContext</param> /// <returns>Client-side validation rules</returns> public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context) { yield return new ModelClientValidationRule { ErrorMessage = FormatErrorMessage(metadata.GetDisplayName()), ValidationType = "streetaddress" }; } }
thanks for the help
Ricka source share