Skip to main content
Community site session details

Community site session details

Session Id :
Customer Service forum

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

(0) ShareShare
ReportReport
Posted on by 249

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

Categories:
  • Suggested answer
    Adrian Begovich Profile Picture
    1,025 Super User 2025 Season 1 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
    249 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
    1,025 Super User 2025 Season 1 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

News and Announcements

Now Available: 2025 Release Wave 2

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 > Customer Service

Featured topics

Product updates

Dynamics 365 release plans