Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Postal Code fields

Avatar

Former Community Member

Hello,


I currently have a postal code field set up to allow a certain format. I am wondering what I would add in so that the user can only enter numbers and letters. Currently with the following script, it allows he user to enter symbols (which I do not want). Thank you in advance for your help!

// form1.page1.subform1.postalCode::exit - (JavaScript, client)

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

    }

  }

}

0 Replies