Skip to main content
Participant
August 19, 2021
Question

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

  • August 19, 2021
  • 2 replies
  • 383 views

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.

This topic has been closed for replies.

2 replies

Participant
August 19, 2021

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.

try67
Community Expert
Community Expert
August 19, 2021

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