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

force a date format in a text box in fillable form

Community Beginner ,
Dec 19, 2022 Dec 19, 2022

Copy link to clipboard

Copied

Hello all, I have been tasked with this request 

1. Have place holder text or Default value display "MM/DD/YYYY" to the user

2. If data is entered, have custom validation the forces a date format of MM/DD/YYYY

 

I know it would be so much easier to just make it a Date data type, but the customer does not like the calendar tool. I have experimented with some of the js and js with RegExpressions solutions (posted in this forum and others) and came close but no success.

 

Is this even possible? is there some js that can add placeholder text

 

Thanks for any help, Richard

TOPICS
JavaScript , PDF forms

Views

344

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 , Dec 19, 2022 Dec 19, 2022

For the first part, use this custom format script:

 

if(/^\s*$/.test(event.value))
    event.value = "MM/DD/YYYY";

 

This script tests the current input. If it is empty, the field displays the default text.  

 

 

Votes

Translate

Translate
Community Expert ,
Dec 19, 2022 Dec 19, 2022

Copy link to clipboard

Copied

For the first part, use this custom format script:

 

if(/^\s*$/.test(event.value))
    event.value = "MM/DD/YYYY";

 

This script tests the current input. If it is empty, the field displays the default text.  

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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 Beginner ,
Dec 19, 2022 Dec 19, 2022

Copy link to clipboard

Copied

Perfect Thom, thanks. I added the validation and it's working exactly as I wanted

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 Beginner ,
Dec 19, 2022 Dec 19, 2022

Copy link to clipboard

Copied

LATEST

This is the validation I used

 

if (event.value) {
var d = util.scand("mm/dd/yyyy", event.value);
if (/^\d{2}\/\d{2}\/\d{4}$/.test(event.value)==false || d==null) {
app.alert("Invalid date string entered. You must enter a date in the following pattern: MM/DD/YYYY");
event.rc = false;
}
}

 

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