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
scottskiblackscottskiblack 

zip code validations from Winter 07 Release notes no longer work?

I got the zip code validations from the Salesforce Winter 07 Release notes, that have many USA zip code validations but they do not work anymore.

For instance the below validation on the Lead object does validate for the USA but also tries to validate when other countries are entered as well, like Canada in the Country field.

OR(
AND(
OR(Country = "United States", LEN(Country) = 0),
LEN(PostalCode) <>5, LEN(PostalCode) <>
10),
NOT(CONTAINS("0123456789", LEFT( PostalCode, 1))),
NOT(CONTAINS("0123456789", MID( PostalCode , 2, 1))),
NOT(CONTAINS("0123456789", MID( PostalCode , 3, 1))),
NOT(CONTAINS("0123456789", MID( PostalCode , 4, 1))),
NOT(CONTAINS("0123456789", MID( PostalCode , 5, 1))),
AND(
LEN(PostalCode) = 10,
OR(
MID( PostalCode , 6, 1) <> "-",
NOT(CONTAINS("0123456789", MID( PostalCode , 7,
1))),
NOT(CONTAINS("0123456789", MID( PostalCode , 8,
1))),
NOT(CONTAINS("0123456789", MID( PostalCode , 9,
1))),
NOT(CONTAINS("0123456789", MID( PostalCode , 10,
1))))
)
)


Why do these validations not work anymore?
rockchick322004rockchick322004
It looks like you have modified the AND and OR from the sample code.  The sample code from Salesforce is, and we have verified that it is still working:

AND(

 OR(Country = "USA", LEN(Country) = 0),

  OR(

   AND(LEN(PostalCode) <>5, LEN(PostalCode) <> 10),

   NOT(CONTAINS("0123456789", LEFT( PostalCode, 1))),

   NOT(CONTAINS("0123456789", MID( PostalCode , 2, 1))),

   NOT(CONTAINS("0123456789", MID( PostalCode , 3, 1))),

   NOT(CONTAINS("0123456789", MID( PostalCode , 4, 1))),

   NOT(CONTAINS("0123456789", MID( PostalCode , 5, 1))),

   AND(

    LEN(PostalCode) = 10,

   OR(

    MID( PostalCode , 6, 1) <> "-",

    NOT(CONTAINS("0123456789", MID( PostalCode , 7, 1))),

    NOT(CONTAINS("0123456789", MID( PostalCode , 8, 1))),

    NOT(CONTAINS("0123456789", MID( PostalCode , 9, 1))),

    NOT(CONTAINS("0123456789", MID( PostalCode , 10, 1)))

   )

  )

 )

)


scottskiblackscottskiblack
Mailing Zip Code

Validates that the contact Mailing Zip/Postal Code is in 99999 or 99999-9999 format if Mailing Country is USA or blank.

Description:
OR( AND( OR(MailingCountry = "USA", LEN(MailingCountry) = 0), LEN(MailingPostalCode) 10), NOT(CONTAINS("0123456789", LEFT( MailingPostalCode, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 2, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 3, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 4, 1))), NOT(CONTAINS("0123456789", MID( MailingPostalCode , 5, 1))), AND( LEN(MailingPostalCode) = 10, OR( MID( MailingPostalCode , 6, 1)
Formula:
Error Message: Zip code must be in 99999 or 99999-9999 format. Error Location: Mailing Zip/Postal Code
rockchick322004rockchick322004
It looks like there has been a change to that sample between Winter '07 release notes and now (probably because it was not working).  Please use the sample in the current online help documentation.  I think what is happening is that having OR() as the outer function makes this rule true more often than you want it to be.

Scott, if your rule has been working all year and then suddenly stopped working recently, please call support to have them log that as case for us to investigate.

Message Edited by mscotton on 11-07-2007 11:16 AM