Can't get custom validation script option to stay selected
I've used Adobe Acrobat Reader quite a bit in past, and have some experience coding, but am new to Adobe Acrobat Pro. I'm working on taking pages from an existing PDF that we have typically printed and filled in with pen and paper and converting them with Acrobat Pro into fillable forms. I have the fields all set up, but I have a series of fields that are for numbers that I need a custom validation script on. The reason is that sometimes these fields are not used, and then they have to have "N/A" put in them. If I just change the format to number, then it doesn't let me type "N/A" in the field.
I found a custom validation script that seems like it should work:
var value = event.value;
if (value === "N/A") {
// Allow "N/A"
event.rc = true;
} else {
// Check if it's a valid number with up to 2 decimal places
var regex = /^\d+(\.\d{1,2})?$/;
if (regex.test(value)) {
event.rc = true;
} else {
event.rc = false; // Reject input if not a valid number
}
}
The problem is every time I select "Run custom validation script:" on the Validate tab for any of the fields, the radio button changes to that option, I can go in with the "Edit..." button and paste the code, but then if I close the Properties window or go to a different tab and come back, the selection has changed back to where the "Field value is not validated" option is selected again, and the code does not appear to have stayed (clicking back to run the custom script and choosing edit gives a blank code window).
I've tried changing the format category to None and doing this again, still have the same problem. Any ideas what I'm doing wrong and how to fix it so the script works? It's probably something simple and obvious, but I'm not finding it. Any help is greatly appreciated!!!
