Expand my Community achievements bar.

SOLVED

Field length restrictions

Avatar

Former Community Member

Hello,

I have a postal code field that is currently restricted to 7 characters including a space. The format is A0A0A0 and the program will automatically put the space in the middle when the user tabs over.  I want the user to enter only 6 characters but If i put that restriction in, it hides one of the letters as it it counts the space as one of the 6 characters.  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 plus still allow for a space. Does this make sense?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Well,

there are several ways to realize this.

The easiest would be the pattern text{A0A 0A0} (with a space at the fourth position) and a limitation to 6 characters.

Another option would be a regular expression that allows both variation of input (limit to 7 characters with space and 6 characters without space), but those expression are another story and everything but trivial.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Well,

there are several ways to realize this.

The easiest would be the pattern text{A0A 0A0} (with a space at the fourth position) and a limitation to 6 characters.

Another option would be a regular expression that allows both variation of input (limit to 7 characters with space and 6 characters without space), but those expression are another story and everything but trivial.

Avatar

Former Community Member

Thank you for your response radzmar. Below is what I have in the exit event currently. So I tried what you suggested by going to paterns but it is still not working for me.

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.");

  }

  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, where the postal code must begin with R.");

    }

  }