raynkel
08-22-2003, 09:20 AM
I have written a Java Script that checks for a valid date in the dd/mm/yyyy format. The problem I have is when I call the date back to display it, it strips out the zeros in the date, ie. 01/01/2002 shows as 1/1/2002. So when a user edits a record that exists it sees the date format as incorrect. Is there a way to force it to show it as 01/01/2002 instead of 1/1/2002? I know I could write script to check how many characters are in the date and check it that way, but would be easier if I could just force it to include the zeros.
Any ideas? Thanks
PS: here is the script
if (aForm.txtEND_DATE.value != ""){
var err=0
var a=aForm.txtEND_DATE.value
if (a.length != 10) err=1
b = a.substring(0, 2)// month
c = a.substring(2, 3)// '/'
d = a.substring(3, 5)// day
e = a.substring(5, 6)// '/'
f = a.substring(6, 10)// year
if (b<1 || b>12) err = 1
if (c != '/') err = 1
if (d<1 || d>31) err = 1
if (e != '/') err = 1
if (f<0 || f>9999) err = 1
if (b==4 || b==6 || b==9 || b==11){
if (d==31) err=1
}
if (b==2){
var g=parseInt(f/4)
if (isNaN(g)) {
err=1
}
if (d>29) err=1
if (d==29 && ((f/4)!=parseInt(f/4))) err=1
}
if (err==1) {
alert("Please enter the End Date in 'mm/dd/yyyy' format");
return(false)
}
Any ideas? Thanks
PS: here is the script
if (aForm.txtEND_DATE.value != ""){
var err=0
var a=aForm.txtEND_DATE.value
if (a.length != 10) err=1
b = a.substring(0, 2)// month
c = a.substring(2, 3)// '/'
d = a.substring(3, 5)// day
e = a.substring(5, 6)// '/'
f = a.substring(6, 10)// year
if (b<1 || b>12) err = 1
if (c != '/') err = 1
if (d<1 || d>31) err = 1
if (e != '/') err = 1
if (f<0 || f>9999) err = 1
if (b==4 || b==6 || b==9 || b==11){
if (d==31) err=1
}
if (b==2){
var g=parseInt(f/4)
if (isNaN(g)) {
err=1
}
if (d>29) err=1
if (d==29 && ((f/4)!=parseInt(f/4))) err=1
}
if (err==1) {
alert("Please enter the End Date in 'mm/dd/yyyy' format");
return(false)
}