테스트 사이트 - 개발 중인 베타 버전입니다

첨부파일 확장자 체크 [정규식]

· 12년 전 · 6317 · 3

파일 첨부 시 첨부파일 확장자가 이미지 파일인지 체크 하는 스크립트 입니다.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>확장자 검사</title>
<script language=javascript>

function checkExt()
{
var IMG_FORMAT = "
\.(bmp|gif|jpg|jpeg|png)$"; //문서만 첨부하게 하려면 이 부분 바꿔주시면 되겠죠? ^^

if((new RegExp(IMG_FORMAT, "i")).test(document.form1.text1.value)) return true;

alert("이미지 파일만 첨부하실 수 있습니다. ");

return false;
}


</script>
</head>
<body>
<form name="form1" method="post" onsubmit="return checkExt()" encType="multipart/form-data">
<input type="file" name="text1">
<input type="submit">
</form>
</body>
</html>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 3개

잘봤어요~
네~~
깨알 지식 감사합니다 ㅎㅎ

게시글 목록

번호 제목
20636
20632
20627
11160
20626
20625
20619
17684
20182
11154
11151
11143
20607
20601
11131
11124
11121
11118
11113
11109
20587
11102
11098
11092
11086