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

Needs help with my date validation script

lpianwi
Level 4
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
Niall_O_Donovan
Level 10
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