These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Regular Expressions Questions

tcb
Registered: May 12 2008
Posts: 15

Am trying to use a five digit zipcode to conditionally display one of two sets of read-only text fields, i.e. Desert.* and Standard.*, containing price info.
 
Would like either to have either:
 
1) No pricing info displayed until AFTER the zipcode field has been entered nand the validation scrip below is run.... or
 
2) Have the default pricing always displayed unless the validation script detects zipcodes of the form 922**, 923** or 925**.
 
Script below is what I've gotten so far, but price fields are frozen and don't toggle when zipcode is changed as I believe they should.
 
Not sure if this is a JavaScript or a REGEX issue, so if anyone can point me in the right direction, would be very grateful.
 
Regards,
 
TCB
  
// Capture 5-character zipcode from PropertyZip form field
 
var zip5 = this.getField("PropertyZip").valueAsString;
  
// Use Regular Expressions to Test First 3 digits of zip5 with 922, 923 and 925.
 
var myRegExp = /92[235]/;
 
if (myRegExp.test(zip5))
{
this.getField("Desert").display = display.visible;
}
else
{
this.getField("Standard").display = display.hidden;
}

My Product Information:
Acrobat Pro 10.0.1, Macintosh
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
Try the following regular expression:

var myRegExp = /^92(2|3|5)/;

The ^ character matches the beginning of the string.


You might also want the test to be something like:

if (zip5.length === 5 && myRegExp.test(zip5)) {or otherwise confirm that the zip code is valid.


It's not clear to me under what conditions you want the Desert and Standard fields to be shown/hidden, so you might want to clarify that.
tcb
Registered: May 12 2008
Posts: 15
Hey George,

Tried your new version of myRegExp, and the compound conditional, but no change in behavior.

The behavior I'm seeking is that when there's a match with any zipcode beginning with 922, 923 or 925; I want a second price list to appear in place of the default price list. I'm currently trying to activate the pricing immediately AFTER the zipcode field is entered by placing the script in the validation section of the PropertyZip field.

The default price list fields can be "hard-coded" into the background PDF of the Form so they're always visible save when the 2nd price list fields are activated and overlay them..... (Think this might be simpler, as zipcode match is an exception case.)

OR both the default and secondary prices can be active fields which are activated/deactivated in a mutually-exclusive fashion based upon the zipcode as I'm doing now.

Is there a way for me to use app.alert to do a javascript version of "printf" such that I can make sure the values are getting set properly at the right times in my script?

If you like I can send you as an attachment the PDF which might reveal at a glance to your eyes something I'm missing.


hher411
Registered: Oct 6 2010
Posts: 3
Hello, tcb.

By now you have probably discovered a solution to this behavior problem, but just in case, you might try this script:

var ZIP5 = this.getField("PropertyZIP").valueAsString;
var myRegExp = /^92(2|3|5)/;

if(myRegExp.test(ZIP5)){this.getField("Desert").display = display.visible; this.getField("Standard").display = display.hidden;}
else{this.getField("Desert").display = display.hidden; this.getField("Standard").display = display.visible;}

Hope this helps.
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
You could just test the substr the value for the first 3 characters of the zip code field

You could use the following validation script for the zip code

var cZipCode = event.value.toString();
cZipTest = cZipCode.substr(0, 3);
if(cZipTest == "922" | cZipTest == "923" | cZipTest == "925") {
// set your special pricing
} else {
// set your default pricing
}

George Kaiser