Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
Views 1360 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 |
---|---|---|---|---|---|
81 | System/OS | [linux] 아파치설치/설정(모니터링) | hooni | 2003.04.23 | 14230 |
80 | System/OS | [linux] 아파치 설치/설정(proxy) | hooni | 2003.04.23 | 13018 |
79 | System/OS | [linux] 아파치설치/설정 - SSI(Server Side Include) | hooni | 2003.04.23 | 13266 |
78 | System/OS | [linux] 아파치설치/설정(CGI부분) | hooni | 2003.04.23 | 14625 |
77 | System/OS | [linux] 아파치설치/설정 | hooni | 2003.04.23 | 14557 |
76 | System/OS | [linux] 새 하드디스크 추가하기..(내공쌓기) | hooni | 2003.04.23 | 13861 |
75 | System/OS | [linux] 기본적인 설정하기(내공쌓기) | hooni | 2003.04.23 | 14060 |
74 | System/OS | [linux] 계정관리하기(내공쌓기) | hooni | 2003.04.23 | 13323 |
73 | System/OS | [linux] 프로그램 설치방법 (내공쌓기) | hooni | 2003.04.23 | 13499 |
72 | System/OS | [linux] 간단한 vi편집기 사용 명령 | hooni | 2003.04.23 | 13541 |
71 | System/OS | [linux] 기본 명령어 (내공쌓기) | hooni | 2003.04.23 | 14387 |
70 | System/OS | [linux] 리눅스 활용 팁^^ | hooni | 2003.04.23 | 14693 |