C
Colin Steadman
I'm a stupid ASP programmer and I dont do Javascript (except for very
simple tasks anyway), and I'm in a bit of a predicament. I've used a
javascript table sorting script from here:
http://www.ipwebdesign.net/kaelisSpace/useful_tableSort.html
This works great except it doesn't sort my UK formatted dates
properly, and I end up with something like this:
Birth Date (dd/mm/yyyy)
=======================
01/10/1990
01/05/1981
01/02/1956
01/08/1977
02/12/1944
The author obviously foresaw this problem and helpfully left a comment
in the script describing how to solve the problem (I have copied the
note at the bottom of this post). The solution is to:
"Modify function isDate if the field has a date in another format.",
I have therefore studied the IsDate function in hopes of making this
change. But having done this I can honestly say I dont have a clue
how it works. I would therefore appreciate any help anyone could give
me to convert this script to work with UK date format (dd/mm/yyyy).
TIA,
Colin
function isDate(str)
{
/* Returns true if the field is mm/dd/yyyy because for some reason,
the browser is not giving the expected NaN for these fields */
var re = /^[01]?[0-9]\/[0-9]?[0-9]\/[12][0-9][0-9][0-9]$/;
if (!str || str.length<1) return false;
if (!re.test(strObject.value)) return false;
else return true;
}
/* parseFloat parses its argument, a string, and returns a floating
point number. If it encounters a character other than a sign (+
or -),
numeral (0-9), a decimal point, or an exponent, it returns the
value
up to that point and ignores that character and all succeeding
characters. Therefore, a regular expression is used to determine
if the field is a date in mm/dd/yyyy format, since it will not sort
the field properly (it does not return NaN and sort the field as a
string, as you might expect it to do). Modify function isDate if
the field has a date in another format. */
simple tasks anyway), and I'm in a bit of a predicament. I've used a
javascript table sorting script from here:
http://www.ipwebdesign.net/kaelisSpace/useful_tableSort.html
This works great except it doesn't sort my UK formatted dates
properly, and I end up with something like this:
Birth Date (dd/mm/yyyy)
=======================
01/10/1990
01/05/1981
01/02/1956
01/08/1977
02/12/1944
The author obviously foresaw this problem and helpfully left a comment
in the script describing how to solve the problem (I have copied the
note at the bottom of this post). The solution is to:
"Modify function isDate if the field has a date in another format.",
I have therefore studied the IsDate function in hopes of making this
change. But having done this I can honestly say I dont have a clue
how it works. I would therefore appreciate any help anyone could give
me to convert this script to work with UK date format (dd/mm/yyyy).
TIA,
Colin
function isDate(str)
{
/* Returns true if the field is mm/dd/yyyy because for some reason,
the browser is not giving the expected NaN for these fields */
var re = /^[01]?[0-9]\/[0-9]?[0-9]\/[12][0-9][0-9][0-9]$/;
if (!str || str.length<1) return false;
if (!re.test(strObject.value)) return false;
else return true;
}
/* parseFloat parses its argument, a string, and returns a floating
point number. If it encounters a character other than a sign (+
or -),
numeral (0-9), a decimal point, or an exponent, it returns the
value
up to that point and ignores that character and all succeeding
characters. Therefore, a regular expression is used to determine
if the field is a date in mm/dd/yyyy format, since it will not sort
the field properly (it does not return NaN and sort the field as a
string, as you might expect it to do). Modify function isDate if
the field has a date in another format. */