Skip to main content

Notifications

Announcements

No record found.

Customer Service forum

How can we allow users to enter time manually in HH:MM AM/PM format

Posted on by 245

How can we allow users to enter time manually in HH:MM AM/PM format ? 

Categories:
  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: How can we allow users to enter time manually in HH:MM AM/PM format

    Hi raki,

    I created a time validation Regex for you that you can play around with here as well as the below JavaScript example. You will need to modify the JavaScript to get it right, but this will give you the general idea.

    var time = Xrm.Page.getAttribute("time").getValue();
    var regularExpression = /(?:[0-1]?[0-9]|[2][1-4]):[0-5]?[0-9]\s?(?:AM|PM)?/;

    if(time.test(regularExpression)) { //Compare the time field to the Regex // The value of the time field is valid. } else { // Warn the user that the value of the time field is invalid. }

    When the value in your time field changes you will need to execute an on change JavaScript file and compare the time field against the Regex to make sure that it is valid. If the time field is valid you do not need to do anything, if it is invalid you can present a warning to the user, or change the field into a valid format.

  • raki Profile Picture
    raki 245 on at
    RE: How can we allow users to enter time manually in HH:MM AM/PM format

    Can you share sample JavaScript?

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: How can we allow users to enter time manually in HH:MM AM/PM format

    Hi Raki,

    You could create a field and then use JavaScript to ensure that users only enter time into the field in the HH:MM AM/PM format.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans