1

I have a requirement to create a validation rule on custom object Address_vod__c. There is a picklist field in the object,'Type'. If 'Type' value is not 'mailing' then restrict to create or edit records for below strings.

  • PO Box
  • Post Office Box
  • POBox
  • PostOffice Box
  • PostOfficeBox
  • P.O. Box
  • P O Box

*strings are case insensitive

My below code fails for this value:

Post Office Box Pobox 5500 E 2nd St

Validation Rule :

AND(
   OR(REGEX(Name,"\\b(?i)(P *O * B *o *x*)\\b"),
      REGEX(Name,"\\b(P. *O. *Box)\\b")
    ),
    NOT( ISPICKVAL(Address_Type_abv__c,"Mailing"))
)
  • 1
    Personally, I think you're making this harder for yourself than you need to. I (obviously) don't know your audience, but this sounds like a case where you're better off simplifying it. Why not validate that the address starts with 'PO Box' or whatever should be the standard, and make the user tweak it accordingly. This doesn't answer your question, but it does ensure your data is consistent. That is of course assuming it's user driven, rather than system/integration driven. – Nick Cook Feb 20 '15 at 12:09
  • If you stripped out all the dots "." and spaces then converted it lower case you would only need to check that the string contains (or starts with) pobox or postofficebox – BarCotter Feb 20 '15 at 12:19
1

I would most likely go with the following REGEX as it should provide you with the most flexibility and capture case insensitive values as well. In addition, it will capture if they fully write out Post Office Box as well.

(?i)\b(?:p\.?\s*o\.?|post\s+office)\s+box\b
0

If read the question, OP is looking for regex validation using a validation rule so the flexibility to reformat the string is not much.

However, I agree with intent of the suggestion by @Nick Cook. Giving more options like this to users,

1) would make them ask for more variations 2) would make it difficult to data cleanse/match 3) would make it difficult if you want to localize

With that said, below regex (validated at RegExPal) seems to work.

Po?s?t?\.? ?Of?f?i?c?e?\.? ?Box

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.