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

Allow user to enter only numbers for a time and populate

Community Beginner ,
Feb 28, 2018 Feb 28, 2018

Copy link to clipboard

Copied

Hi Experts

I have a form that I am creating and i would like the user to only enter 4 digits to represent HHMM and validate to HH:MM I have found a script that does this but for a date, and I was wondering if there was someone who could help out? Thanks in advance..

The thread i found for date validation is here: Allow user to enter only numbers for a date and populate with slashes, then validate (JavaScript)

Daniel

TOPICS
Acrobat SDK and JavaScript , Windows

Views

402

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

LEGEND , Mar 04, 2018 Mar 04, 2018

You could also use one field for each time entry and format as "Time" with a format of "hHH;MM" which is 24 hour format and it will apply a limit of 00 - 23 for the hours and 00-59 for the minutes.

This is a basic time sheet calculation. You can split the enterd value at the ":". Then multiply the hours by 60 and add to the minutes. This will provide the number of minutes since midnight. The difference in minutes between 2 fields will be the elapsed time which can be converted back to hours and m

...

Votes

Translate

Translate
Community Expert ,
Mar 01, 2018 Mar 01, 2018

Copy link to clipboard

Copied

You need to write a script that validates that the input is indeed 4 digits long, and that the first two are between "00" and "23" and the second two are between "00" and "59". That's pretty much it...

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 ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

Thanks for your reply try67, sorry i was looking for help as in if someone was able to help me write the code as I am not Javascripter myself. As I stated I am looking for the user to add 4 digits, (into TimeA & TimeB) then the validation script will add the ':' in between the digits then validate as a 'proper' time. I then have another script that calculates TimeB-TimeA. I can add an arbitrary mask that will give the desired 'effect' but it doesnt see it as "time" and the existing script i have doesn't calculate it properly. Any help at all is really appreciated.

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
LEGEND ,
Mar 04, 2018 Mar 04, 2018

Copy link to clipboard

Copied

LATEST

You could also use one field for each time entry and format as "Time" with a format of "hHH;MM" which is 24 hour format and it will apply a limit of 00 - 23 for the hours and 00-59 for the minutes.

This is a basic time sheet calculation. You can split the enterd value at the ":". Then multiply the hours by 60 and add to the minutes. This will provide the number of minutes since midnight. The difference in minutes between 2 fields will be the elapsed time which can be converted back to hours and minutes.

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