Expand my Community achievements bar.

SOLVED

Postal Code fields

Avatar

Former Community Member

Hello,

Right now I have a postal code field set up to allow a certain format. Right now it will only let the user enter letters, numbers and spaces. I want to put a restriction on the field so that the user cannot enter a space in the field. I  am having problems doing this though. Below is the script I am using in the EXIT event. Please let me know if you can offer any help.

Thank you,

NikDK

if

(!(this.isNull)) {

var str = this.rawValue;

if (str.length != 6) {

xfa.host.messageBox("Please enter a six character postal code in the format A9A9A9 without spaces. The postal code must begin with R.");

}

else {

var regExp = /^([R]\d[A-Z]\d[A-Z]\d)$/i;

if (regExp.test(str)) {

str

= str.toUpperCase();

this.rawValue

= str.substring(0,3) + " " + str.substring(3,6);

}

else {

xfa.host.messageBox("Please enter the postal code in the format A9A9A9 without spaces. The postal code must begin with R.");

}

}

}

1 Accepted Solution

Avatar

Correct answer by
Level 10

You can try placing the below code in Change event with java Script.

This will restrict the input to numbers and letters only.

if (xfa.event.change.match(/[0-9\A-Z\a-z]/) == null)
     xfa.event.change = "";

Thanks

Srini

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

You can try placing the below code in Change event with java Script.

This will restrict the input to numbers and letters only.

if (xfa.event.change.match(/[0-9\A-Z\a-z]/) == null)
     xfa.event.change = "";

Thanks

Srini

Avatar

Former Community Member

now here's another question about the postal code field. I want the user to enter only 6 characters. If i put that restriction in then because of the space, it counts the space as one of the 6 characters and cuts off one of the letters or numbers. If I change it to allow 7 characters, then the user can enter the whole 7 characters, but I only want them to enter 6. Does this make sense?