날짜 형식 입력 받은 값 확인하기 정보
HTML 날짜 형식 입력 받은 값 확인하기본문
<script language="javascript">
function gogogo() {
var ri = check_date(document.all.year.value,document.all.month.value,document.all.day.value)
if (ri == 0) {
alert('정상적인 형식');
} else if (ri == 1) {
alert('년(?)이 잘못 되었습니다');
} else if (ri == 2) {
alert('월이 잘못 되었습니다');
} else if (ri == 3) {
alert('일이 잘못 되었습니다');
}
}
function check_date(year, month, day) {
var dat_option = year % 4;
year = parseInt(year, 10);
month = parseInt(month, 10);
day = parseInt(day, 10);
if (isNaN(year) == true) { return 1; }
if (year < 1970) { return 1; }
if (isNaN(month) == true) { return 2; }
if (isNaN(day) == true) { return 3; }
if (day < 1 || day > 31) { return 3; }
if (month == 2) {
if (((dat_option == 0) && (day > 29)) || ((dat_option != 0) && (day > 28)) ) { return 3; }
} else if ((month == 4) ||
(month == 6) ||
(month == 9) ||
(month == 11)) {
if (day > 30) { return 3; }
} else if ((month == 1) ||
(month == 3) ||
(month == 5) ||
(month == 7) ||
(month == 8) ||
(month == 10) ||
(month == 12)) {
if (day > 31) { return 3; }
} else {
return 2;
}
return 0;
}
</script>
<input type="text" name="year"> 년
<input type="text" name="month"> 월
<input type="text" name="day"> 일
<input type="button" value="확인" onclick="gogogo();"><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
function gogogo() {
var ri = check_date(document.all.year.value,document.all.month.value,document.all.day.value)
if (ri == 0) {
alert('정상적인 형식');
} else if (ri == 1) {
alert('년(?)이 잘못 되었습니다');
} else if (ri == 2) {
alert('월이 잘못 되었습니다');
} else if (ri == 3) {
alert('일이 잘못 되었습니다');
}
}
function check_date(year, month, day) {
var dat_option = year % 4;
year = parseInt(year, 10);
month = parseInt(month, 10);
day = parseInt(day, 10);
if (isNaN(year) == true) { return 1; }
if (year < 1970) { return 1; }
if (isNaN(month) == true) { return 2; }
if (isNaN(day) == true) { return 3; }
if (day < 1 || day > 31) { return 3; }
if (month == 2) {
if (((dat_option == 0) && (day > 29)) || ((dat_option != 0) && (day > 28)) ) { return 3; }
} else if ((month == 4) ||
(month == 6) ||
(month == 9) ||
(month == 11)) {
if (day > 30) { return 3; }
} else if ((month == 1) ||
(month == 3) ||
(month == 5) ||
(month == 7) ||
(month == 8) ||
(month == 10) ||
(month == 12)) {
if (day > 31) { return 3; }
} else {
return 2;
}
return 0;
}
</script>
<input type="text" name="year"> 년
<input type="text" name="month"> 월
<input type="text" name="day"> 일
<input type="button" value="확인" onclick="gogogo();"><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]</div>
추천
0
0
댓글 0개