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.
Can you share sample JavaScript?
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.