Feb
26
2008
26
2008
Javascript for validating a date
Javascript for validating a date.
Pass month, day, year as parameters. This function will return true if the date is valid.
// Author: arunmvishnu.com
function validDate(month, day, year){
if(month =='0' || day =='0' || year=='0'){
return false;
}
switch(month){
case '1': //** jan
case '3': //** March
case '5': //** May
case '7': //** July
case '8': //** Aug
case '10': //** Nov
case '12': //** Dec
if(day >=1 && day <= 31){
return true;
} else {
return false;
}
case '4': //** APRIL
case '6' : //** JUNE
case '9' : //** SEPTEMBER
case '11' : //** NOVEMBER
if(day >=1 && day <= 30){
return true;
} else {
return false;
}
case '2' : // Feb
if(isLeapYear(year)){
if(day >=1 && day <= 29){
return true;
}
} else if(day >=1 && day <= 28){
return true;
} else {
return false;
}
default:
return false;
}
}
function isLeapYear(year){ // Checking wdr a year is leap year or not
if(year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)){
return true;
} else {
return false;
}
}
The full js file can be dodnloaded from here
Tags: java script, Programming
Related Posts
Latest Posts
- Your Facebook account hacked? Here’s how to fix it
- Indian Railway Enabled VRM System to travel without the printout of e-ticket
- Amazon Launches $199 Kindle Fire Android Tablet
- Download Windows 8
- How to change APN settings in iPhone iOS Beta 7
- Steve Jobs Resigns as CEO of Apple
- How to open camera app when the iPhone is locked?
- Firefox 5 released
- Download Firefox 4
- How to run Turbo C IDE on Windows 7
Tags
apple
c and cpp
Cheats
download
downloads
Entertainment
error
Film
friendship
Fun
gadgets
Games
gmail
google
greetings
india
Internet
iphone
java script
linux
love
mac
microsoft
mobile
News
office
onam
Personal
photos
Programming
review
Security
software
source code
technology
Tips & Tricks
video
videos
virus
web
web development
windows
windows 7
worm
yahoo

An article by