Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bug in the date validation code with IE

Status
Not open for further replies.

neetu

Programmer
May 25, 2001
11
IN
There is an error in the below mentioned code which is used to check for the date
i. e when the date is entered ....the js code written checks if its a valid date or not.
it works fine with netscape ..but gives an error icon on the status bar for IE.

function checkdate(date_a)
{

var err = 0;
a = date_a.value;

if (a.length != 10) err = 1;

b1 = a.substring(0,2); //date
var b=parseInt(b1);

c = a.substring(2,3); //'-'

d1 = a.substring(3,5); //month
var d=parseInt(d1);

e = a.substring(5,6); //'-'

f1 = a.substring(6,10); //year
f = parseInt(f1);
if (isNaN(f)) alert("INVALID YEAR FORMAT - Enter in yyyy format");


//basic error checking

if (b < 1 || b > 31) alert(&quot;INVALID DAY ! PL Enter Date between 01 and 31&quot;);
if (c != '-') alert(&quot;INVALID FORMAT ! Please enter a -(Hifen) after entering date&quot;);
if (d < 1 || d > 12) alert(&quot;INVALID MONTH ! PL Enter Month between 1 and 12&quot;);
if (e != '-') alert(&quot;INVALID FORMAT ! Please enter a -(Hifen) after entering month&quot;);
if (f < 1900 || f > 9999) alert(&quot;INVLAID YEAR ! PL Enter Year between 1900 and 9999&quot;);

//advanced error checking
//month with 30days

if (d == 4 || d == 6 || d == 9 || d ==11)
if (b >= 31)
alert(&quot;INVALID DAY ! Date entered must be within 31&quot;);

//month = feb & leap year
if (d == 2)
{
g = f/4;

if (b > 29) alert(&quot;Wrong input ! Date entered must be within 30&quot;);
if (b == 29)
if((f%100 == 0 || f%4 != 0) && (f%400 != 0))
alert(&quot;Wrong input ! A leap year cannot have the entered date&quot;);
}

}

i accept the date as below in a form named f1 & check it by onchange( )

<input type=&quot;text&quot; size=&quot;11&quot; maxlength=&quot;11&quot; name=&quot;date&quot; onchange=&quot;checkdate(document.f1.date);&quot;>
 
This is the line that's causing your problems:
Code:
f1 = a.substring(6,10); //year
It's because you've also called your form f1. If you rename one of them then it should work.
Hope that's clear
regards,
Iain :)
 
thnx a million Iain !

it really worked....it shouldve striked me before...

but thnx anyways!!!!!

regards

neetu :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top