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

Unable to get date validation to work properly - JS

gary742
Registered: Jun 4 2010
Posts: 7

Hi. I am sorta new at scripting. I want to validate a date entry in a text field. I've searched and found example scripts on how to do this, but when I code the script in the form, any text I enter in the field does not pass the edit, I always get the error message. Can anyone point out the (probably) obvious oversight I am making? Here is the simple code:

----------
form1.#subform[0].TextField1::exit - (JavaScript, client)

var dateStr = this.rawValue;
var regExp = /^\d{1,2}\/\d{1,2}\/d{4}$/;

if (!regExp.test(dateStr)) {
xfa.host.messageBox("Please enter the date in the format MM/DD/YYYY.");
}
---------

If I enter an "x" in the field I get the message box error.
If I enter any valid date in mm/dd/yyyy format I get the same message.

I have am using LiveCycle Designer ES v8, but I have tried with the prior version with the same result.

TIA,

Gary, NJ

gary742
Registered: Jun 4 2010
Posts: 7
Well, with a little more T&E I discovered the example I had pulled from somewhere was incorrect. Evidently the pattern is coded incorrectly.When changed to:

var regExp = /^\d{1,2}\/\d{1,2}\/\d{4}$/;

the script works just fine.