Skip to content

Commit

Permalink
feat : 금액 유효성 검사 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeonseo-Jo committed Oct 26, 2023
1 parent e4fa747 commit 939378b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions week2/assign2/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ const renderOptions = (event) => {
<option class="add-category__option">쇼핑</option>`);
};

//숫자만 입력하도록 구현하는 함수
const checkNumber = (event) => {
if (isNaN(event.key)) {
alert("숫자만 입력하세요");
}
event.target.value = event.target.value.replace(/[^0-9]/g, "");
};

// 금액에 숫자만 입력하도록 하는 핸들러 함수
const handleEnterAmount = () => {
const newAmount = $(".add-amounts__input");

newAmount.addEventListener("keyup", checkNumber);
};

// 리스트 추가 함수
const addNewList = () => {
const newType = $('input[name="type"]:checked').value;
Expand Down Expand Up @@ -203,3 +218,5 @@ handleOpenListAddModal();
handleChangeType();
handleAddList();
handleCloseListAddModal();

handleEnterAmount();

0 comments on commit 939378b

Please sign in to comment.