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


HCL Notes and Domino: Tips & Tricks

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


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 HCL 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 1, 2020 using MDY format style and back slash format separator: 9/1/2020, 09/20 09/01/2020, 9/1/20, 09/01/20, 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 HCL Business Partner "IVE Technologies LLC (dba NotesMail)" as the developer.

HCL BP NotesMail sells a Domino web developer tool called "Web Date Picker for HCL Notes and Domino". It includes the IsNotesDate() JavaScript function for international date validation, as well as, an optional web date picker interface (graphical display calendar control pop-up). Web Date Picker 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 11/10/9/8 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 HCL Notes and Domino integration code
// ©1997-2020 IVE Technologies LLC (dba NotesMail) - www.notesmail.com/Crucial-Notes-tools
//
// 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 HCL Notes and Domino integration code
// ©1997-2020 IVE Technologies LLC (dba NotesMail) - www.notesmail.com/Crucial-Notes-tools
//
// 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 HCL BP NotesMail in a product called Web Date Picker: http://www.notesmail.com/WebDatePicker]

.