Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3546 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
207 | Develop |
[c] 다중연결 서버 만들기 #3 - poll() 사용
![]() |
hooni | 2013.04.23 | 7459 |
206 | Develop |
[doc] C언어 문법 설명서
![]() |
hooni | 2013.04.23 | 7440 |
205 | Develop | [js] 사진첩에 쓸 내용 - 마우스 오버로 바꾸기 | hooni | 2013.04.23 | 7438 |
204 | Develop | [js] 실행되는 디렉토리 확인하는 스크립트.. | hooni | 2013.04.23 | 7436 |
203 | Develop | [android] Calling activity function from separate class | hooni | 2016.11.15 | 7426 |
202 | Develop |
[PHP] Mac OS에서 PHP 7 설치하기
![]() |
hooni | 2018.05.11 | 7399 |
201 | Develop |
[doc] C++언어 문법 설명서
![]() |
hooni | 2013.04.23 | 7314 |
200 | Develop | [js] 서서히 나타나는 화면.. ㅋㅋ | hooni | 2013.04.23 | 7186 |
199 | Develop |
[ios] 동영상 플레이어 샘플 (for Local File)
![]() |
hooni | 2017.02.07 | 7134 |
198 | Develop |
[ios] Facebook Cache 갱신하는 함수
![]() |
hooni | 2017.02.27 | 7061 |
197 | Develop | [js] 자바스크립트 escape()를 PHP로 받기 | hooni | 2013.04.23 | 6894 |
196 | Develop | [android] How can I place app icon on launcher home screen? | hooni | 2016.11.15 | 6379 |