Expand my Community achievements bar.

Validation of Canadian Postal Codes

Avatar

Level 2

Canadian postal codes follow the A9A 9A9 format.

In my display validation pattern, I have  text{A9A 9A9}

In my edit validation pattern, I have text{A9A 9A9}|text{A9A9A9}

In my validation pattern, I have text{A9A 9A9}

I also have a JavaScript validation running client side.

It reads:

form1.#subform[0].Section1.PostalCode::validate - (JavaScript, client)

this.rawValue = this.rawValue.toUpperCase();

Given these paramaters, I am stumped as to why I keep getting the following validation error: "The value you entered for Postal Code in valid."

Any thoughts?

3 Replies

Avatar

Level 10

Your uppercase code should be on the exit event of the field. The validation pattern works by testing against the display pattern.

Or you could put xfa.event.change = xfa.event.change.toUpperCase(); on the change event of the field.

Avatar

Level 2

This appears to work. Many thanks.

Avatar

Level 1

Try this:

event.value = event.value.toUpperCase();

if(event.value != "")

{

// validate Canadian postal code;

event.rc = /^(?!.*[DFIOQU])[A-VXY][0-9][A-Z][0-9][A-Z][0-9]$/.test(event.value);

if(event.rc == false)

{

  app.alert("Please enter a correct Canadian Postal code", 1, 0);

  this.resetForm([event.target.name]);

}

}