Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

Validation of Time field with two valid formats


Not applicable
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


Not applicable
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) {"Hour entered must be between 1 and 12", "Invalid Time", 0, 0);


if (nMinute < 0 || nMinute > 59 || nMinute == NaN) {"Minute entered must be between 0 and 59", "Invalid Time", 0, 0);




Adobe Enterprise Support


Not applicable
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.



Not applicable
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