Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1353 댓글 0
How to Filter Numbers Of A String
Not really jQuery at all:
number = number.replace(/\D/g, '');
That regular expression, /\D/g
, matches any non-digit. Thus the call to .replace()
replaces all non-digits (all of them, thanks to "g") with the empty string.
edit — if you want an actual *number value, you can use parseInt()
after removing the non-digits from the string:
var number = "number32"; // a string
number = number.replace(/\D/g, ''); // a string of only digits, or the empty string
number = parseInt(number, 10); // now it's a numeric value
If the original string may have no digits at all, you'll get the numeric non-value NaN
from parseInt
in that case, which may be as good as anything.
[출처] https://stackoverflow.com/questions/4460595/jquery-filter-numbers-of-a-string
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
769 | Develop |
[ios] Xcode에서 특정 파일만 ARC 따로 설정하는 방법
![]() |
hooni | 2017.03.29 | 1082 |
768 | Develop | [js] 스크롤 이벤트 막기 | hooni | 2015.04.14 | 1091 |
767 | Develop | [ios] APNS, Remote Push 수신 시점에서 앱의 3가지 실행 상태 | hooni | 2018.10.19 | 1093 |
766 | Develop |
[ios] Xcode의 디버그 모드에서 콜스택
![]() |
hooni | 2015.01.03 | 1112 |
765 | Develop |
[c] FSN 온라인 코딩 테스트 (Sorting, Binary Search)
![]() |
hooni | 2015.06.26 | 1128 |
764 | Develop |
'2014 모바일 개발 트렌드' 발표자료입니다.
![]() |
hooni | 2014.10.02 | 1137 |
763 | Develop | [ios] 로컬에 있는 html 실행하기 | hooni | 2015.02.10 | 1143 |
762 | Develop |
[ios] StoryBoard(xib) 없이 프로젝트 만들기
![]() |
hooni | 2015.02.12 | 1156 |
761 | Develop | [ios] 상위 ViewController 가져오기 | hooni | 2015.10.12 | 1168 |
760 | Develop | [ios] Did UIScrollView End Scrolling? | hooni | 2016.04.19 | 1172 |
759 | Develop |
[ios][swift] 초간단 To-do Memo
![]() |
hooni | 2016.06.27 | 1185 |
758 | Develop | [ios] 최상위 ViewController 가져오기 | hooni | 2015.10.12 | 1198 |