Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Postal Code Validations

Avatar

Former Community Member

Hello,

I currently have a feild that is set up for postal codes. The user enters a 6 digit number without spaces, in a format of A3A 3A3 (letter, number, letter, number, letter, number). When the user tabs over, it automaticallly displays the space inbetween.  I am wondering if it is possible to have the field only allow postal codes that begin with R or S, and if so, how would I achieve this.

Thank you in advance for your help,

Nik

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

The problem was related to mixing validation patterns and validation error handling with custom validation scripting. Display and validation patterns and validation error handling had to be removed for the script to work properly.

Steve

View solution in original post

10 Replies

Avatar

Former Community Member

Try this...

// 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 = /^([RS]\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 or S.");

    }

  }

}

Steve

Avatar

Former Community Member

HI Steve, thank you again for your help. This seems to be working to an

extent. If I put in the correct postal code format, I am still getting an

error message.

Avatar

Former Community Member

Please disregard the previous email. It seems to be working fine now. Not

sure why. Thanks again for all of your help.

Avatar

Former Community Member

Nope i was wrong, its not working. It brings up a error message even if you enter the correct format. Any suggestions?

Avatar

Former Community Member

If you can send the form to stwalker.adobe@gmail.com I'd be happy to take a look.

Steve

Avatar

Correct answer by
Former Community Member

The problem was related to mixing validation patterns and validation error handling with custom validation scripting. Display and validation patterns and validation error handling had to be removed for the script to work properly.

Steve

Avatar

Former Community Member

Hi Steve,

I'm wondering how I would restrict the field from allowing symbols.

Avatar

Level 1

Help - I created a field for postal codes last year and cannot for the life of me remember how to do it again

Avatar

Level 10

Maybe look at validation patterns?  Which country (or countries) are you targeting?

Avatar

Level 1

Hi - it's okay. I don't need a validation pattern, was just struggling with formatting it so it would work correctly. It is now. Thanks    

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----