function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SR9887SR9887 

Need Help on Validation Rule to identify PO value in the Street Address on account Object.

We have Validation Rule on Street Field on Account Object. Below is the Validation Rule

AND(NOT(ISNEW()),ISCHANGED(Street),OR(CONTAINS(UPPER(Street),'P.O'),CONTAINS(UPPER(Street),'P.O.'),CONTAINS(UPPER(Street),'PO BOX'),CONTAINS(UPPER(Street),'POST BOX'),CONTAINS(UPPER(Street),'POST OFFICE'),CONTAINS(UPPER(Street),'PO.'),CONTAINS(UPPER(Street),'POBOX'),CONTAINS(UPPER(Street),'PO')))

Use Case: To Restrict the User to not to enter Any Post Box Number in the Street Field. But the above validation rule is working for all other combinations - except for 'PO'.

It is getting triggered for any Street String which contains 'po' letters in it. It should basically identify the PO word in the Street String.

 

 

Anne ToneyAnne Toney
Hello,
I am not an expert but I just want to sa that to modify the validation rule to correctly identify the word "PO" in the Street field, you can use word boundaries (\b) to ensure that the letters "PO" are not part of a larger word. Here's an updated version of the validation rule:
AND(
    NOT(ISNEW()),
    ISCHANGED(Street),
    OR(
        CONTAINS(UPPER(Street), ' P.O '),
        CONTAINS(UPPER(Street), ' P.O. '),
        CONTAINS(UPPER(Street), ' PO BOX '),
        CONTAINS(UPPER(Street), ' POST BOX '),
        CONTAINS(UPPER(Street), ' POST OFFICE '),
        CONTAINS(UPPER(Street), ' PO. '),
        CONTAINS(UPPER(Street), ' POBOX '),
        REGEX(UPPER(Street), '(\b)PO(\b)')
    )
)


In this updated rule, the REGEX function is used to check for the presence of the word "PO" as a separate word using word boundaries (\b). This ensures that it matches only if "PO" is not part of a larger word. https://www.mcdvoice.onl/
frinksa lilinasfrinksa lilinas
Hello,

Added spaces before and after "PO" in each condition to ensure it matches whole words. This helps prevent false positives when "PO" appears as part of other words. Used BEGINS function to check if the Street field starts with "PO " (with a space after "PO"). This ensures it identifies "PO" as a separate word at the beginning of the string.

AND(
    NOT(ISNEW()),
    ISCHANGED(Street),
    OR(
        CONTAINS(UPPER(Street), ' P.O '),
        CONTAINS(UPPER(Street), ' P.O.'),
        CONTAINS(UPPER(Street), ' PO BOX '),
        CONTAINS(UPPER(Street), ' POST BOX '),
        CONTAINS(UPPER(Street), ' POST OFFICE '),
        CONTAINS(UPPER(Street), ' PO. '),
        CONTAINS(UPPER(Street), ' POBOX '),
        BEGINS(UPPER(Street), 'PO ')
    )
)