Expand my Community achievements bar.

Needs help with my date validation script

Avatar

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");  
  xfa.host.setFocus("DateTimeField1");
}

Thanks

v/r

Tammy

1 Reply

Avatar

Level 10

Hi,

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

{YYYYMMDD} | {DD-MM-YY} | {DD-MM-YYYY} | {DD/MM/YY} | {DD/MM/YYYY} | {MM-DD-YY}

The Display pattern would remain the same {YYYYMMDD}

Hope that helps,

Niall