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
GeorgeTrommelenGeorgeTrommelen 

validation rule on Dutch postal codes

Can anybody help me with avalidation rule for Dutch postal codes according the next format?
 
4 figures+one space+ 2 letters
 
eg.: 1234 AB
 
look forard to hear solutions.
 
George
jpizzalajpizzala
Add this as the formula for your validation rule:

Code:
AND( DutchPostalCode__c <> "" , NOT( REGEX( DutchPostalCode__c , "[0-9]{4}[\\s]{1}[a-z|A-Z]{2}" ) ) )

Where DutchPostalCode__c is the field you are validating.

 I'm not too good with regular expressions, but this seems to work as far as I can tell.

NOTE: I added the DutchPostalCode__c <> "" bit just in case the field is not required.  Without this, the validation rule prevent the record from being saved if the value is empty.  If the field is required through field level security, you can remove everything except for the NOT clause.


Message Edited by jpizzala on 06-02-2008 12:57 PM

Message Edited by jpizzala on 06-02-2008 12:59 PM
GeorgeTrommelenGeorgeTrommelen
Hi again,
 
Thanks again for youer help, now they want to add foreign postal codes, can we make a dependancy towards the country field?
 
Look forward to hear from you
 
George
 
jpizzalajpizzala
How do you mean "make a dependancy towards the country field"?

Do you want to make the postal code field required only when a certain country is selected?  If so, you can accomplish this through a validation rule.

Or do you want the validation rule to be more robust and allow for a different validation for each postal code type, based on the Country field?  For instance, if United States is chosen in the Country field the Postal Code field would validate for a United States postal code format and if Japan was chosen in the Country field the Postal Code field would validate for a Japanese postal code, etc?  To accomplish this, you could expand on the validation rule for the Postal Code field.  Just add some logic that will execute upon the value of the Country field via CASE and ISPICKVAL formula functions.

This could get a bit messy, however, depending on how many countries you want to validate.  If it gets too large, I would suggest creating an Apex class to process the validation instead of the standard formula-driven validation rule approach.


Message Edited by jpizzala on 07-09-2008 02:53 PM