Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3536 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
651 | Develop | [android] 안드로이드 동영상 스트리밍 예제 2 | hooni | 2015.01.02 | 6254 |
650 | Develop | How to Test SMTP AUTH using Telnet | hooni | 2018.04.05 | 6298 |
649 | Develop |
[ios] Objective-C 프로퍼티의 strong, weak, assign
![]() |
hooni | 2014.03.17 | 6373 |
648 | Develop | [android] How can I place app icon on launcher home screen? | hooni | 2016.11.15 | 6377 |
647 | Develop | [js] 자바스크립트 escape()를 PHP로 받기 | hooni | 2013.04.23 | 6894 |
646 | Develop |
[ios] Facebook Cache 갱신하는 함수
![]() |
hooni | 2017.02.27 | 7061 |
645 | Develop |
[ios] 동영상 플레이어 샘플 (for Local File)
![]() |
hooni | 2017.02.07 | 7132 |
644 | Develop | [js] 서서히 나타나는 화면.. ㅋㅋ | hooni | 2013.04.23 | 7184 |
643 | Develop |
[doc] C++언어 문법 설명서
![]() |
hooni | 2013.04.23 | 7313 |
642 | Develop |
[PHP] Mac OS에서 PHP 7 설치하기
![]() |
hooni | 2018.05.11 | 7399 |
641 | Develop | [android] Calling activity function from separate class | hooni | 2016.11.15 | 7424 |
640 | Develop | [js] 실행되는 디렉토리 확인하는 스크립트.. | hooni | 2013.04.23 | 7436 |