WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   Datum prüfen (http://www.wcm.at/forum/showthread.php?t=22494)

Tower 30.05.2001 11:25

Datum prüfen
 
ich würde gern ein Datum in einem Formular mit hilfe
von einem JavaScript auf seine Richtigkeit prüfen.
Weiß jemand das Scipt dazu????

Dr. Mabuse 30.05.2001 11:50

http://developer.irt.org/script/1.htm

<script language="JavaScript"><!--
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isDate (day,month,year) {
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.

var today = new Date();
year = ((!year) ? y2k(today.getYear()):year);
month = ((!month) ? today.getMonth():month-1);
if (!day) return false
var test = new Date(year,month,day);
if ( (y2k(test.getYear()) == year) &&
(month == test.getMonth()) &&
(day == test.getDate()) )
return true;
else
return false
}

if (isDate(31,2,1997))
document.write("Valid");
else
document.write("Invalid");
//--></script>



Update: dem snowman sein script ist aber besser :-)

snowman 30.05.2001 11:52

http://www.iisfaq.com/Articles/131/

gruss,
snowman


Alle Zeitangaben in WEZ +2. Es ist jetzt 04:02 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag