• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Date Formatting

Explorer ,
Aug 21, 2020 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

TOPICS
How to , PDF forms

Views

701

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
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 21, 2020 Aug 21, 2020

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

 

if (theDate.length == 8 ) {

 

Votes

Translate

Translate
Community Expert ,
Aug 21, 2020 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;
}

Votes

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
community guidelines
Explorer ,
Aug 21, 2020 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.

Votes

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
community guidelines
Community Expert ,
Aug 21, 2020 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). 

Votes

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
community guidelines
Community Expert ,
Aug 21, 2020 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 ) {

 

Votes

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
community guidelines
Explorer ,
Aug 21, 2020 Aug 21, 2020

Copy link to clipboard

Copied

Perfect, thank you.

Votes

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
community guidelines
Explorer ,
Sep 09, 2020 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.

Votes

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
community guidelines
Community Expert ,
Sep 09, 2020 Sep 09, 2020

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Explorer ,
Sep 09, 2020 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;
}

Votes

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
community guidelines
Community Expert ,
Sep 09, 2020 Sep 09, 2020

Copy link to clipboard

Copied

I actually meant the one you modified. 

Votes

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
community guidelines
Explorer ,
Sep 09, 2020 Sep 09, 2020

Copy link to clipboard

Copied

It is the same script.  I undid the changes.

Votes

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
community guidelines
Explorer ,
Sep 10, 2020 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;
}

Votes

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
community guidelines
Community Expert ,
Sep 10, 2020 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;
}

Votes

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
community guidelines
Explorer ,
Sep 10, 2020 Sep 10, 2020

Copy link to clipboard

Copied

LATEST

Perfect, thank you

Votes

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
community guidelines