Expand my Community achievements bar.

Script for Patterns to be applied differently if US or CDN

Avatar

Level 2

Hello,

In my form I need to have a script for a field which allows for validations/patterns for Postal Codes for CDN/Zip Codes for the US.

This script needs to check the value of my country field and if it is the US then it should only allow an entry of text{99999} for the zip code and if anyone enters anything different then it should come up with a message saying entry can only be ##### or something like that.  If it is Canada then it should check that the pattern being entered is text{A9A 9A9} and then of course a message of some sort.

I know this is easy to do within the form, however becuase I need to check the country and then apply different rules I am not quite sure how to go about it.  If you have any ideas please let me know ... actual script examples would be appreciated and where to place it would be really great.

I am using FormCalc, however Java scripts is fine to.  thx!

3 Replies

Avatar

Level 8

You can create both fields, one for US and one for Canada then show/hide the appropriate one based on the country they select. That way you don't have to do a bunch of scripting.

In the exit and docReady event of your country dropdown you can put:

if (this.rawValue=="US"){//Or whatever value is assigned to United States
USField.presence="visible";
CanadaField.presence="hidden";
}
else{//default state
USField.presence="hidden";
CanadaField.presence="visible";
}

Kyle

Avatar

Level 2

o.k. .... after much thought and fighting with code I decide to abandon this effort.  I do thank you for your info.  I decided to approach it from a simpler standpoint and just have the postal code validation set to both patterns and then my inbound handler will send any errors back to the user in an email for them to deal with.  thx for your time.

Avatar

Level 10

If you decide to revisit this you can change picture values on the fly with format.picture.value.

if (this.rawValue == 1) {

    PostalCode.format.picture.value = "A9A 9A9";

}