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

force a date format in a text box in fillable form

Community Beginner ,
Dec 19, 2022 Dec 19, 2022

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
3.0K
Translate
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
1 ACCEPTED SOLUTION
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.  

 

 

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

View solution in original post

Translate
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 ,
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.  

 

 

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

Translate
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

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

Translate
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
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;
}
}

 

Translate
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