1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<script type="text/javascript">
<!--
    //날짜 유효성검사
    if ( !isValidDate('2014-11-31') ) {
        alert('에러');
 
    } else {
        alert('정상');
    }
     
 
    function isValidDate(param) {
        try
        {
            param = param.replace(/-/g,'');
 
            // 자리수가 맞지않을때
            if( isNaN(param) || param.length!=8 ) {
                return false;
            }
             
            var year = Number(param.substring(0, 4));
            var month = Number(param.substring(4, 6));
            var day = Number(param.substring(6, 8));
 
            var dd = day / 0;
 
             
            if( month<1 || month>12 ) {
                return false;
            }
             
            var maxDaysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
            var maxDay = maxDaysInMonth[month-1];
             
            // 윤년 체크
            if( month==2 && ( year%4==0 && year%100!=0 || year%400==0 ) ) {
                maxDay = 29;
            }
             
            if( day<=0 || day>maxDay ) {
                return false;
            }
            return true;
 
        } catch (err) {
            return false;
        }                      
    }
//-->
</script>

+ Recent posts