Javascript International Date Validation V2.0

The code below can be used for any application and supports international
date formats. The function is called using 3 parameters as described in the
code comments.

The code supports the same valid time data type functionality as a 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 April 1st, 2000 using MDY format style and back slash
format separator: 4/1/2000, 04/01, 04/01/2000, 4/1/00, 04/01/00, etc.

The code can be copy/pasted into the $$HTMLHead field, but be sure to disable
the submit button if the code fails. Feel free to use the code, but please do
not
remove the comment which denotes myself as developer since I have seen my
code plagiarized in the past in a United Kingdom Notes publication.

NOTE: If you are using a global application replicating on servers which do not
have the same date format settings you can access the NotesInternational class
in a LotusScript agent prior to opening a form which can set a flag or cookie
to determine the JavaScript call parameters.

If you are looking for a virtual web calendar pop-up visit Ivesco.com at
http://www.ivesco.com.
CR := @Newline;

"<SCRIPT LANGUAGE=\"JavaScript\">" + CR +
"DateErrorMsg = \"Field Contains Incorrect Value\\n\\nUnable to interpret Time
or Date\";" + CR +
"if (!IsNotesDate(document.forms[0].txt_date1.value, 1, 1))
alert(DateErrorMsg);" + CR +

"function IsNotesDate(txt_date, num_style, num_sep) {" + CR +
"//" + CR +
"// INTERNATIONAL DATE VALIDATION" + CR +
"// Coded by Lance Zakin - zakin@bigfoot.com" + CR +
"//" + CR +
"// PARAMETERS" + CR +
"// txt_date: Date (text data type) i.e. 01/01/2000" + CR +
"// num_style: Date Format Style (number data type) i.e. 1 = MDY, 2 = DMY, 3
= YMD" + CR +
"// num_sep: Date Format Separator (number data type) i.e. 1 = back slash, 2
= dash, 3 = period" + CR +
"//" + CR +
"if (txt_date.replace(/ /g, \"\") == \"\" || txt_date.toLowerCase() ==
\"today\" || txt_date.toLowerCase() == \"tomorrow\" || txt_date.toLowerCase()
== \"yesterday\") return 1;" + CR +
"len = txt_date.length;" + CR +
"if (num_sep == 1) sep = \"/\";" + CR +
"if (num_sep == 2) sep = \"-\";" + CR +
"if (num_sep == 3) sep = \".\";" + CR +
"parse1 = txt_date;" + CR +
"pos1 = parse1.indexOf(sep);" + CR +
"data1= parseInt(parse1.substring(0, pos1));" + CR +
"parse2 = parse1.substring(pos1+1, len);" + CR +
"pos2 = parse2.indexOf(sep);" + CR +
"if (pos2 != -1) data2 = parseInt(parse2.substring(0, pos2)); else data2 =
parseInt(parse2.substring(0, len));" + CR +
"parse3 = parse2.substring(pos2+1, len);" + CR +
"data3 = parseInt(parse3.substring(0, len));" + CR +
"if (data3 < 50) data3 = 2000 + data3;" + CR +
"var theDate = new Date();"+ CR +
"txt_date = data1.toString() + sep + data2.toString() + sep +
data3.toString();" + CR +
"if (pos2 == -1 && (num_style == 1 || num_style == 2)) { data3 =
theDate.getYear() + 1900;" + CR +
"txt_date = data1.toString() + sep + data2.toString() + sep +
data3.toString();" + CR +
"}" + CR +
"if (pos2 == -1 && num_style == 3) { data3 = theDate.getYear() + 1900;" + CR +
"txt_date = data3.toString() + sep + data1.toString() + sep +
data2.toString();" + CR +
"}" + CR +
"var theDate = new Date(txt_date);"+ CR +
"if (num_style == 1) mos = data1; else mos = data2;" + CR +
"if (theDate.getMonth() != mos-1) return 0;" + CR +
"return 1;" + CR +
"}" + CR +
"</script>"
This was last published in November 2000

Dig Deeper on Domino Resources - Part 7

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchExchange

SearchContentManagement

Close