input file size check regular expression
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page import="testJSP.Stringutil"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javaScript" language="javascript" defer="defer">
function userImgUpload(obj){
var maxSize = 50 * 1024; // kb
var fileSize = obj.files[0].size;
var fileValue = obj.value.toLowerCase();
if (fileSize > maxSize) {
alert(fileSize+" | "+maxSize);
alert("50KB미만의 사진을 첨부해 주세요.");
return;
}
var regularExpression = "(.jpg)|(.pdf)|(.gif)|(.png)";
if (fileValue.match(regularExpression) == null){
alert("jpg, pdf, gif, png 파일만 올릴 수 있습니다.");
return ;
}
}
</script>
</head>
<body>
<input type="file" onChange="userImgUpload(this)" />
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page import="testJSP.Stringutil"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script type="text/javaScript" language="javascript" defer="defer">
function userImgUpload(obj){
var maxSize = 50 * 1024; // kb
var fileSize = obj.files[0].size;
var fileValue = obj.value.toLowerCase();
if (fileSize > maxSize) {
alert(fileSize+" | "+maxSize);
alert("50KB미만의 사진을 첨부해 주세요.");
return;
}
var regularExpression = "(.jpg)|(.pdf)|(.gif)|(.png)";
if (fileValue.match(regularExpression) == null){
alert("jpg, pdf, gif, png 파일만 올릴 수 있습니다.");
return ;
}
}
</script>
</head>
<body>
<input type="file" onChange="userImgUpload(this)" />
</body>
</html>