Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
Views 3438 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 |
---|---|---|---|---|---|
85 | System/OS | [linux] 텔넷, FTP 텍스트 모드에서 사용 | hooni | 2003.04.23 | 12705 |
84 | System/OS | [linux] 랜카드가 2개 일 때 네트워크 설정 | hooni | 2003.04.23 | 31113 |
83 | System/OS | [linux] 아파치설치/설정 - 알리어싱(aliasing) | hooni | 2003.04.23 | 52418 |
82 | System/OS | [linux] 아파치설치/설정 - 사용인증 | hooni | 2003.04.23 | 15885 |
81 | System/OS | [linux] 아파치설치/설정(모니터링) | hooni | 2003.04.23 | 14938 |
80 | System/OS | [linux] 아파치 설치/설정(proxy) | hooni | 2003.04.23 | 13847 |
79 | System/OS | [linux] 아파치설치/설정 - SSI(Server Side Include) | hooni | 2003.04.23 | 13938 |
78 | System/OS | [linux] 아파치설치/설정(CGI부분) | hooni | 2003.04.23 | 15448 |
77 | System/OS | [linux] 아파치설치/설정 | hooni | 2003.04.23 | 15238 |
76 | System/OS | [linux] 새 하드디스크 추가하기..(내공쌓기) | hooni | 2003.04.23 | 14693 |
75 | System/OS | [linux] 기본적인 설정하기(내공쌓기) | hooni | 2003.04.23 | 14859 |
74 | System/OS | [linux] 계정관리하기(내공쌓기) | hooni | 2003.04.23 | 14260 |