- function CheckDate(strDate) {
- var reg = /^(/d{4})([-])(/d{2})([-])(/d{2})/;
- if (!reg.test(strDate)) {
- alert("/u65e5/u671f/u683c/u5f0f/u4e0d/u6b63/u786e!/n/u6b63/u786e/u683c/u5f0f/u4e3a:2004-01-01");
- return false;
- }
- var ss = strDate.split("-");
- var year = ss[0];
- var month = ss[1];
- var date = ss[2];
- if (!checkYear(year)) {
- return false;
- }
- if (!checkMonth(month)) {
- return false;
- }
- if (!checkDate(year, month, date)) {
- return false;
- }
- return true;
- }
- function checkYear(year) {
- if (isNaN(parseInt(year))) {
- alert("/u5e74/u4efd/u8f93/u5165/u6709/u8bef,/u8bf7/u91cd/u65b0/u8f93/u5165!");
- return false;
- } else {
- if (parseInt(year) < 1950 || parseInt(year) > 2050) {
- alert("/u5e74/u4efd/u5e94/u8be5/u57281950-2050/u4e4b/u95f4!");
- return false;
- } else {
- return true;
- }
- }
- }
- function checkMonth(month) {
- if (isNaN(parseInt(month))) {
- alert("/u6708/u4efd/u8f93/u5165/u6709/u8bef,/u8bf7/u91cd/u65b0/u8f93/u5165!");
- return false;
- } else {
- if (parseInt(month) < 1 || parseInt(month) > 12) {
- alert("/u6708/u4efd/u5e94/u8be5/u57281-12/u4e4b/u95f4!");
- return false;
- } else {
- return true;
- }
- }
- }
- function checkDate(year, month, date) {
- var daysOfMonth = CalDays(parseInt(year), parseInt(month));
- if (isNaN(parseInt(date))) {
- alert("/u65e5/u671f/u8f93/u5165/u6709/u8bef,/u8bf7/u91cd/u65b0/u8f93/u5165!");
- return false;
- } else {
- if (parseInt(date) < 0 || parseInt(date) > daysOfMonth) {
- alert("/u65e5/u671f/u5e94/u8be5/u57281-" + daysOfMonth + "/u4e4b/u95f4!");
- return false;
- } else {
- return true;
- }
- }
- }
- function CalDays(year, month) {
- var date = new Date(year, month, 0);
- return date.getDate();
- }
- function isLeapYear(year) {
- if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
- return true;
- } else {
- return false;
- }
- }
验证年月日 js
最新推荐文章于 2024-07-20 11:37:30 发布