Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1353 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1101 | System/OS | [linux] 프로그램 설치방법 (내공쌓기) | hooni | 2003.04.23 | 13495 |
1100 | System/OS | [linux] 계정관리하기(내공쌓기) | hooni | 2003.04.23 | 13319 |
1099 | System/OS | [linux] 기본적인 설정하기(내공쌓기) | hooni | 2003.04.23 | 14056 |
1098 | System/OS | [linux] 새 하드디스크 추가하기..(내공쌓기) | hooni | 2003.04.23 | 13856 |
1097 | System/OS | [linux] 아파치설치/설정 | hooni | 2003.04.23 | 14554 |
1096 | System/OS | [linux] 아파치설치/설정(CGI부분) | hooni | 2003.04.23 | 14625 |
1095 | System/OS | [linux] 아파치설치/설정 - SSI(Server Side Include) | hooni | 2003.04.23 | 13260 |
1094 | System/OS | [linux] 아파치 설치/설정(proxy) | hooni | 2003.04.23 | 13012 |
1093 | System/OS | [linux] 아파치설치/설정(모니터링) | hooni | 2003.04.23 | 14222 |
1092 | System/OS | [linux] 아파치설치/설정 - 사용인증 | hooni | 2003.04.23 | 15150 |
1091 | System/OS | [linux] 아파치설치/설정 - 알리어싱(aliasing) | hooni | 2003.04.23 | 51453 |
1090 | System/OS | [linux] 랜카드가 2개 일 때 네트워크 설정 | hooni | 2003.04.23 | 30132 |