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

How to allow various time formats into a field (HH:MM, hh:mm, HHMM or HMM) but always output HH:MM?

New Here ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Is there a way to allow various time formats into a "Time" field but have the field contents display HH:MM?

Using the Format tab of the field's Properties, it seems to allow only one format, but the PDF users want more flexibility. Specifically, to input with or without a comma, but output in the field with a comma.

Thanks.

TOPICS
Acrobat SDK and JavaScript

Views

52

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
community guidelines
Community Expert ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

Yes, but you'll need to write a custom validation (and possibly also keystroke and format) script to do it.

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
community guidelines
New Here ,
Aug 19, 2021 Aug 19, 2021

Copy link to clipboard

Copied

LATEST

Thank you for your thoughts on the matter. I know that some scripting is needed. 

I've written a validation script and attached it to the "Properites >Validate" tab, which allows HH:MM, HHMM, hh:mm, or hhmm
But I can't figure out how to format the output to always be HH:MM

For this second part, I thought maybe a script in "Properites > Calculation"  or "Properites > Format" to do the following
(1) get field value
(2) strip out non digits
(3) set field to date format of HH:MM

For example
var enteredTime = getField("TimeField").value;
var numberPattern = /\d+/g;
var extractNum = enteredTime.match( numberPattern );
event.value = (util.printd("HH:MM", extractNum));

But it does not work. I am not familiar with JavaScript or Regular Expressions, so maybe I'm doing something wrong. Or maybe I'm not using the "util.printd" function properly. I'm lost.

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