web date field validation for domino - isnotesdate() javascript function


IBM Notes and Domino: Tips & Tricks

Web Date Field Validation for Domino - IsNotesDate() JavaScript function
September 24, 2012


By Lance Zakin, IBM CASA, CAAD
Notes and Domino
IBM BP NotesMail
The code below can be used for any application and supports international date formats. The function is called using 5 parameters as described in the code comments. The code supports the same valid time data type functionality as a Lotus Notes client including date format styles "MDY, DMY, YMD", and date format separators "back slash, dash, period" which depends on the server date setting.

i.e. Valid formats for September 1st, 2012 using MDY format style and back slash format separator: 9/1/2012, 09/12, 09/01/2012, 9/1/12, 09/01/12, etc.

The code can be copy/pasted into the JS Header object, but be sure not to run the submit button code if validation fails. Feel free to use the code, but please do not remove the comment which denotes IVE Technologies as the developer.

NotesMail sells a Domino web developer tool called "Web Date Picker for Lotus Notes". It includes the IsNotesData() Javacsript function for international date validation, as well as, an optional web date picker interface (graphical display calendar control pop-up). Web Date Picker for Lotus Notes allows a Domino Developer to add a web date picker to automatically populate a field on a web form: http://www.notesmail.com/WebDatePicker

NOTE: Domino 8.5.x does not natively support a date picker on the web: Domino calendar features that are not supported on the Web

JavaScript code: Validation example
function validation() {
txtDate = document.forms[0].datDate.value;
txtDateLen = document.forms[0].datDate.value.length;
DateErrorMsg1 = "Date is a required field.\n\nPlease click the calendar icon to select a date.";
if (txtDate == "" || txtDateLen == 1) { alert(DateErrorMsg1); return; }
DateErrorMsg2 = "Field Contains Incorrect Value\n\nUnable to interpret Time or Date";
//
// Web Date Picker for IBM Notes and Domino
// ©1997-2013 NotesMail - www.notesmail.com
//
// INTERNATIONAL WEB DATE FIELD VALIDATION
//
// PARAMETERS
// txt_date: Date (text data type) i.e. 01/01/2013
// num_style: Date Format Style (num data type) i.e. 1 = MDY, 2 = DMY, 3 = YMD
// num_sep: Date Format Separator (num data type) i.e. 1 = back slash, 2 = dash, 3 = period
// num_span: Date Span (num data type) i.e. 1 = ignore, 2 = less equal today, 3 = greater equal today
// num_date: Date Compare (num data type) i.e. 1 = ignore, 2 = return date data type value
//
if (!IsNotesDate(txtDate,1,1,1,1)) { alert(DateErrorMsg2); return; }
document.forms[0].button.value="Processing...";
document.forms[0].submit();
}

JavaScript code: isNotesDate() function
function IsNotesDate(txt_date, num_style, num_sep, num_span, num_date) {
//
// Web Date Picker for IBM Notes and Domino
// ©1997-2013 NotesMail - www.notesmail.com
//
// INTERNATIONAL WEB DATE FIELD VALIDATION
//
// PARAMETERS
// txt_date: Date (text data type) i.e. 01/01/2013
// num_style: Date Format Style (num data type) i.e. 1 = MDY, 2 = DMY, 3 = YMD
// num_sep: Date Format Separator (num data type) i.e. 1 = back slash, 2 = dash, 3 = period
// num_span: Date Span (num data type) i.e. 1 = ignore, 2 = less equal today, 3 = greater equal today
// num_date: Date Compare (num data type) i.e. 1 = ignore, 2 = return date data type value
//
[The full code has been removed since it is now maintained by NotesMail in a product called Web Date Picker: http://www.notesmail.com/WebDatePicker]

.