Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
Views 3459 Comment 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
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
1105 | Etc | WM미통기 - 10. 조건부확률 | hooni | 2015.04.20 | 2248 |
1104 | Develop |
[ios] VIN Scanner (VIN barcode) 스캐너
![]() |
hooni | 2017.09.16 | 2262 |
1103 | Develop | [git] 쉬운 버전관리 Git 설명 | hooni | 2015.08.18 | 2263 |
1102 | Develop |
[ios] 비디오,네트워크,소셜로그인 테스트
![]() |
hooni | 2017.04.04 | 2272 |
1101 | Etc | 수리통계학 : 표본공간과 사상-1 | hooni | 2015.04.20 | 2284 |
1100 | Develop |
[ios] UIWebView를 이용한 로컬 HTML 파일 표시
![]() |
hooni | 2015.01.02 | 2300 |
1099 | System/OS | [linux] yum 업데이트 시 커널 제외하기 | hooni | 2014.09.11 | 2314 |
1098 | Develop | [ios] UIView 계층구조 | hooni | 2015.01.03 | 2317 |
1097 | Develop |
[ios] iOS 앱 아이콘을 만드는 유틸
![]() |
hooni | 2015.01.03 | 2317 |
1096 | Develop |
리팩토링 계획안
![]() |
hooni | 2017.05.15 | 2345 |
1095 | Develop | [ios] Crashlytics, Fabfic 설치/설정 | hooni | 2016.07.21 | 2358 |
1094 | Develop |
[ios] 오브젝티브C→스위프트, 코드 변환 손쉽게
![]() |
hooni | 2015.08.07 | 2369 |