Highlighted

Date Formatting

New Here ,
Aug 21, 2020

Copy link to clipboard

Copied

I know there are a bunch of posts on this subject, but what I am looking for is simple.  I am not a JavaScript expert by a long shot.

What I am looking for is that when a user enters a text field and types in say 01232021 and leaves that box, it will be formatted at 01/23/2021

Adobe Community Professional
Correct answer by Karl Heinz Kremer | Adobe Community Professional

So this time, it does show up, I guess I have to add a space, try this:

 

if (theDate.length == 8 ) {

 

TOPICS
How to, PDF forms

Views

90

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Date Formatting

New Here ,
Aug 21, 2020

Copy link to clipboard

Copied

I know there are a bunch of posts on this subject, but what I am looking for is simple.  I am not a JavaScript expert by a long shot.

What I am looking for is that when a user enters a text field and types in say 01232021 and leaves that box, it will be formatted at 01/23/2021

Adobe Community Professional
Correct answer by Karl Heinz Kremer | Adobe Community Professional

So this time, it does show up, I guess I have to add a space, try this:

 

if (theDate.length == 8 ) {

 

TOPICS
How to, PDF forms

Views

91

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Aug 21, 2020 0
Adobe Community Professional ,
Aug 21, 2020

Copy link to clipboard

Copied

For that to work, you need JavaScript. You first need to make sure that you have a string of the correct length (and potentially only containing digits), then you break it up into the three parts and assemble again with the correct delimiters. When you use the following as a custom validation script, it should do the job:

 

var theDate = event.value;
if (theDate.length == 8) {
   var month = theDate.substring(0,2);
    var day = theDate.substring(2,4);
    var year = theDate.substring(4);
    event.value = month + "/" + day + "/" + year;
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
New Here ,
Aug 21, 2020

Copy link to clipboard

Copied

Thank you Karl for the script.  When entering it in, I am getting s SyntaxError: missing : after property ID 3: at line 4.

It looks the same as the other lines, not sure what it is asking.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
Adobe Community Professional ,
Aug 21, 2020

Copy link to clipboard

Copied

Hmmm.. there is something missing, even though I copied and pasted from Acrobat. 

 

The "if" line should be like this:

 

if (theDate.length == 8) {

 

For whatever reason, the forum software took the "8)" and converted it to an emoji (which is not being displayed, but when you copy and paste that line back into the forum editor, it shows up). 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
Adobe Community Professional ,
Aug 21, 2020

Copy link to clipboard

Copied

So this time, it does show up, I guess I have to add a space, try this:

 

if (theDate.length == 8 ) {

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
New Here ,
Aug 21, 2020

Copy link to clipboard

Copied

Perfect, thank you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Aug 21, 2020 0
New Here ,
Sep 09, 2020

Copy link to clipboard

Copied

Hi Karl,

 

Hope your still checking.

I need to remove the YYYY from the above script.  I tried just removing the var year line and everything after the day in the event.value

 

When I preview the form now the / does not show.  I changed the length to 6 but that did not work either.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 09, 2020 0
Adobe Community Professional ,
Sep 09, 2020

Copy link to clipboard

Copied

Can you please post the script you are trying to use.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 09, 2020 0
New Here ,
Sep 09, 2020

Copy link to clipboard

Copied

Sorry it was the one up earlier in the string:

 

var theDate = event.value;
if (theDate.length == 8 ) {
var month = theDate.substring(0,2);
var day = theDate.substring(2,4);
var year = theDate.substring(4);
event.value = month + "/" + day + "/" + year;
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 09, 2020 0
Adobe Community Professional ,
Sep 09, 2020

Copy link to clipboard

Copied

I actually meant the one you modified. 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 09, 2020 0
New Here ,
Sep 09, 2020

Copy link to clipboard

Copied

It is the same script.  I undid the changes.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 09, 2020 0
New Here ,
Sep 10, 2020

Copy link to clipboard

Copied

This is what I tempted:

var theDate = event.value;
if (theDate.length == 5 ) {
var month = theDate.substring(0,2);
var day = theDate.substring(2,4);
event.value = month + "/" + day;
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 10, 2020 0
Adobe Community Professional ,
Sep 10, 2020

Copy link to clipboard

Copied

Sorry for the delay, but family and job come first 🙂 

 

Try this:

 

var theDate = event.value;
if (theDate.length == 4) {
   var month = theDate.substring(0,2);
    var day = theDate.substring(2);
    event.value = month + "/" + day;
}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 10, 2020 0
bfry2461 LATEST
New Here ,
Sep 10, 2020

Copy link to clipboard

Copied

Perfect, thank you

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 10, 2020 0