자바스크립트2 [front-end] input type file에서 특정 확장자 제외시키기 txt이외의 파일은 전부 가능한테 txt파일만 제외시켜달라는 요청을 받았다. 파일첨부 위 같은 형태가 n개가 반복되고 그 n개 모두에게 같은 이벤트를 할당해야 하는 상황 우선은 페이지가 렌더링 된 후 초기화 할 때 아래와 같이 이벤트를 매핑시켜준다. $("input[type='file']").change($M.proc.fileChange); 그러고 난 후에 change 이벤트가 발생하면 e.preventDefault를 호출하여도 파일은 이미 첨부된 상태라 의미가 없었다. 그래서 해당 input을 부시고 다시 생성하기로 결정 $M.proc.fileChange = function(e) { if("text/plain".equals(e.target.files[0].type)) { var _parent = $(".. 2023. 3. 16. 전화번호를 누가 이상하게 넣어놨을때 function(telno) { telno = telno.replace(/ /g, ''); var result = ''; switch(telno.length) { case 8: // 1588-1588 result = telno.substring(0,4) + '-' + telno.substring(4,8); break; case 9: // 02-123-1234 result = '02-' + telno.substring(2,5) + '-' + telno.substring(5,9); break; case 10: if(telno.startsWith('02')) { // 서울 result = '02-' + telno.substring(2,6) + '-' + telno.substring(6,10); } else {.. 2023. 2. 9. 이전 1 다음