Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Validation of Time field with two valid formats


Former Community Member
I want to allow the enter of time as

h:mm or as hh:mm

For example, 1:30 or 12:30 or 01:30 would not generate a user entry error message.

and have been unable to do so.

I would welcome advice.

4 Replies


Former Community Member
Hi Howard,

To do what you want you will need to write some javascript to do the validation. You can attach the script to the validate event of the field you need to validate. You can use the script below as a starting point.

if (form1.DateTimeField1.rawValue != null && form1.DateTimeField1.rawValue != "") {

var sTime = DateTimeField1.rawValue; //Copy time entered

var nColon = sTime.indexOf(":"); //Find location of :

var nHour = parseInt(sTime.substr(0, nColon), 10); //Get Hour

var nMinute = parseInt(sTime.substr(nColon+1, sTime.length), 10); //Get minute

if (nHour < 1 || nHour > 12 || nHour == NaN) {

xfa.host.messageBox("Hour entered must be between 1 and 12", "Invalid Time", 0, 0);


if (nMinute < 0 || nMinute > 59 || nMinute == NaN) {

xfa.host.messageBox("Minute entered must be between 0 and 59", "Invalid Time", 0, 0);




Adobe Enterprise Support


Former Community Member
Isn't all of that JavaScript overkill? This can be accomplished with a simple edit pattern of 'H:MM'.

This allow you to type in '1:30' and will automatically convert '01:30' to '1:30'. You can also change your display pattern to control how it appears on the form.



Former Community Member
hi Justin the validation pattern works fine but the text that is typed is retained within the field. So the validation just shows up and doesnt clear the textfield. Please say me how to clear the Textfield after validation message