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;
}
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.