티스토리 뷰
728x90
input 태그 숫자 입력 시 세자리 수 콤마를 입력하게 하는 코드, 기존과는 다르게 jQuery를 사용해서 새로운 attribute를 만들고 HTML 의 input 태그에 아래와 같이 적용하면 된다.
$(document).on('keyup','input[inputmode=numeric]',function(event){
this.value = this.value.replace(/[^0-9]/g,''); // 입력값이 숫자가 아니면 공백
this.value = this.value.replace(/,/g,''); // ,값 공백처리
this.value = this.value.replace(/\B(?=(\d{3})+(?!\d))/g, ","); // 정규식을 이용해서 3자리 마다 , 추가
});
사용예제
<input type="text" inputmode="numeric">
728x90
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- springboot
- jQuery
- mybatis
- Bash tab
- rocky
- Github Status
- 북리뷰
- Spring Security
- Mac
- 프로페셔널 스튜던트
- window
- LocalDate
- Java
- oracle
- Spring
- 베리 심플
- mybatis config
- localtime
- elasticsearch
- intellij
- config-location
- Kotlin
- LocalDateTime
- maven
- 오라클
- input
- docker
- svn
- Linux
- JavaScript
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함