HI,
i am entering date in the format ‘yyyymmdd’ in the form.
once i click save button , it must validate the date .
any validation code ,please.
Thanks & Regards, drams.
<i> </i><script type="text/javascript"> function isValidDate(year, month, date) { var flagDate = new Date(year, month, date); if (year != flagDate.getFullYear() || month != flagDate.getMonth() || date != flagDate.getDate()) { return false; } return true; } alert(isValidDate(2000, 1, 29)); alert(isValidDate(2001, 1, 28)); alert(isValidDate(2001, 1, 29)); alert(isValidDate(2007, 12, 1)); </script>
<i> </i><script type="text/javascript"> function getDayInMonth(year, month) { if (month == 2) { if (year % 4 == 0 && (year <= 1582 || (year % 100 != 0 || year % 400 == 0))) { return 29; } return 28; } if (month > 7) month ++; return (month % 2 == 0) ? 30 : 31; } <i> </i> function isValidDate(year, month, date) <i> </i> { <i> </i> for (i = 0; i < arguments.length; i++) <i> </i> { <i> </i> if (isNaN(arguments[i]) || arguments[i] < 1) return false; <i> </i> } <i> </i> if (month > 12 || date > getDayInMonth(year, month)) return false; <i> </i> return true; <i> </i> } <i> </i> alert(isValidDate(2000, 2, 29)); <i> </i> alert(isValidDate(2001, 4, 31)); <i> </i> alert(isValidDate(2100, 2, 29)); <i> </i> alert(isValidDate(1500, 2, 29)); </script>
Help @drams spread the word by sharing this article on Twitter...