Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Needs help with my date validation script


Level 4

I have date field in my form I am working on, and when the date picker is used, it works fine with the date format as YYYYMMDD. However, when it is manually entered wrong, it only pops up the error message, but tabs to the next field. Is there a script that will set the focus back to the field, and only tabs out of it when the user input is incorrect. I wrote the below script, but it is not working, and I do not know why it is not.

Create a date() for parsing information.
var sDate = Date.rawValue;
var oDate = util.scand("yyyymmdd", sDate);    
// Store date values.
var nYear = oDate.getFullYear();
var nMonth = oDate.getMonth() + 1; 
var nDay = oDate.getDate();

if(nDay > 31 || nDay < 1 || nMonth > 12 || nMonth < 1){  
   xfa.host.messageBox("Please enter the number using numerical characters only in the format YYYYMMDD");  




1 Reply


Level 10


One option instead of a validation script is to specify multiple date patterns in the Edit tab (Object > Field palette and click Patterns).


The Display pattern would remain the same {YYYYMMDD}

Hope that helps,