Skip to main content
Participant
August 30, 2013
Answered

Format Date Form Field in Adobe Acrobat Pro

  • August 30, 2013
  • 4 replies
  • 26890 views

Thanks in advance for your help. I have date fields in an Acrobat form. Is it possible to create a script to format a date as either MM/DD/YYYY or MM/DD/YY? In other words, if someone enters MM/DD/YYYY, the date would be accepted and MM/DD/YY would also be accepted. Thanks, again.

This topic has been closed for replies.
Correct answer try67

Good point. To be honest, it could be either. The dates entered are generally birthdates and signature dates. The birthdates could be 19XX or 20XX. The signature dates would be 20XX. I'm just trying to avoid an error dialog when the user enters a date as mm/dd/yy or m/d/yy. Thanks for your insight and help.


I think an error dialog is better than an unclear value. Millions (if not

more) of dollars and thousands (if not more) of man hours were spent on

solving the Y2K bug. Don't fall in the same trap...

4 replies

radivojk44011214
Participant
December 23, 2017

When entering date in dd/mm/yyyy format into received Adobe PDF forms, I always got a JavaSript error telling that date format should be m/d/y. JavaSript then  automatically reverts my entered date to this format ! And this with any Internet browser, even with default languages set to English UK or French and Windows 7 date  set to European format.

                  

I found many complaints and questions on this subject on the WEB, but except some very technical Java programming suggestions, I found no solutions.

But finally, playing with one of PDF forms, I FOUND A SIMPLE SOLUTION !

  1. 1. DOWNLOAD THE REQUIRED PDF FORM AND SAVE IT AS PDF FILE, THEN OPEN THIS FILE
  2. 2. Click on  EDIT, then PREFERENCES and select JAVASCRIPT from a roll-down list
  3. 3. UNCHECK the "Enable Acrobat JavaScript"
  4. 4. Click OK
  5. 5. Now, you can ENTER DATE IN DD/MM/YYYY FORMAT and JavaScript will not modify it !

Cheers !

Inspiring
December 23, 2017

But will it be a valid date and will it be the date the user wanted entered?

Also you will be eliminating a lot of other JavaScript actions that maybe needed by the form. An example would be the computing of the age based on the date of birth entered.

One can use the RegExp option for the custom keystroke, custom format, and custom validation to get this to work, but one still needs to deal with the issue of dates that could be spanning more than 100 years.

radivojk44011214
Participant
December 23, 2017

Well, this was concerning of entering a birth date into the received form.

And after disabling JavaScript, I could enter date in any wanted form and it was kept as it is when printing or sending the response via email. There was no other modification done by disabling JavaScript. So, it did work!

Maybe for particular applications like calculating the age from entered date it won't work, but then it would require programming knowledge that average user having to fill-in the form doesn't have, nor needs for such a simple usage.

Participant
February 21, 2017

Under text field's property > option, you can limit amount of character in the text field.

Then, under validation, choose "Run custom validation script" with the following script:

//Force the text field only accept numeric value//

var alphaNumericPatt = /^[0-9]*$/;
event.rc = alphaNumericPatt.test(event.value);

//Break the string into three group of numbers//

var dobD = event.value.substring(0,2)
var dobM = event.value.substring(2,4)
var dobY = event.value.substring(4,8)

// Combine the string with "/" as divider to the format like this DD/MM/YYYY //
var dobFull = dobD + "/" + dobM + "/" + dobY

event.value = dobFull

September 2, 2013

To avoid possible confusion due to inconsistent user inputs, have you thought of having 3 combo boxes, one each for day, month and year?

Combo boxes are a good way to force the user to pick a specific response.

The user's choices from the combo boxes can then be imported into a text field on your form.

try67
Community Expert
Community Expert
September 2, 2013

I would recommend against that, as that involves a lot of scripting changing the days drop-down according to the selected month and year.

Just use a text field with a pre-defined date format. That will take care of all of these issues for you.

try67
Community Expert
Community Expert
August 30, 2013

You can write your own custom validation script to allow that, but I would

recommend against it.

Participant
August 30, 2013

Thanks for your response. There is really no other way to control the format of the date? I would just like the date field to accept either mm/dd/yyyy or mm/dd/yy. (It would be great if the date could automatically be converted to mm/dd/yyyy, but if I enter anything other than mm/dd/yyyy, a dialog box appears indicating that the data was not in correct format.) Thanks, again!

try67
Community Expert
Community Expert
August 30, 2013

How would you make that conversion? Let's say the user enters "12/10/50".

Is that 2050 or 1950?