The Validate
a Date snippet demonstrates validating a date based on a date range
that the user enters.
In this example, the user selects a date from a calendar and
then specifies the start and end dates to validate the specified
date against. The form compares the specified date against the date
range and reports whether the specified year, month, and day are
valid.
To add script to the Validate buttonform1.#subform[0].Button1::click - (JavaScript, client)
Status.clearItems(); //Clear the status listbox.
// Create a date() for parsing information.
var sDate = Date.rawValue;
var oDate = util.scand("yyyy-mm-dd", sDate);
if(oDate == null)
{
xfa.host.messageBox("Pleae enter a valid date.");
exit;
}
// Store date values.
var nYear = oDate.getFullYear();
var nMonth = oDate.getMonth() + 1; // 0 based
var nDay = oDate.getDate();
// Validation flags.
var bStartYear = false;
var bEndYear = false;
var bStartMonth = false;
var bEndMonth = false;
var bStartDay = false;
var bEndDay = false;
// Validate the year range.
if((StartYear.rawValue == null) || (StartYear.rawValue <= nYear))
bStartYear = true;
if((EndYear.rawValue == null) || (EndYear.rawValue >= nYear))
bEndYear = true;
if(bStartYear && bEndYear)
Status.addItem("valid year");
else
Status.addItem("invalid year");
// Validate the month range.
if((StartMonth.rawValue == null) || (StartMonth.rawValue <= nMonth))
bStartMonth = true;
if((EndMonth.rawValue == null) || (EndMonth.rawValue >= nMonth))
bEndMonth = true;
if(bStartMonth && bEndMonth)
Status.addItem("valid month");
else
Status.addItem("invalid month");
// Validate the day range.
if((StartDay.rawValue == null) || (StartDay.rawValue <= nDay))
bStartDay = true;
if((EndDay.rawValue == null) || (EndDay.rawValue >= nDay))
bEndDay = true;
if(bStartDay && bEndDay)
Status.addItem("valid day");
else
Status.addItem("invalid day");
To see similar examples,
visit the LiveCycle Developer Center.
|
|
|