Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1090 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1161 | Develop | [iOS] Xcode 불필요한 캐시 삭제하기 | hooni | 2021.10.12 | 1333 |
1160 | Develop | [swift] 실행시간 측정하기 | hooni | 2021.09.14 | 651 |
1159 | Develop | [vim] vim 명령으로  문자 제거하기 (remove 65279 bomb) | hooni | 2021.02.03 | 1138 |
1158 | Develop | [js] show/hide 이벤트 감시 (Observing show/hide event) | hooni | 2021.02.03 | 2548 |
1157 | Develop | [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 | hooni | 2021.01.29 | 1359 |
1156 | Develop | [swift] NotificationCenter 간단 예제 | hooni | 2021.01.27 | 8089 |
1155 | Develop | [kotlin] 코틀린 안드로이드 앱 버전/빌드 정보 | hooni | 2020.12.15 | 797 |
1154 | Develop | [ubuntu] 우분투 18.04에 PHP5 설치하기 | hooni | 2020.11.14 | 925 |
1153 | System/OS | [펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들 | hooni | 2020.10.15 | 923 |
1152 | Develop | [js] Text 값을 클립보드에 복사하기 | hooni | 2020.10.10 | 663 |
1151 | System/OS | Apache CORS 설정 1 | hooni | 2020.09.04 | 2687 |
1150 | System/OS | How to Install and Use wget on Mac | hooni | 2020.09.03 | 1257 |