Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3459 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1141 | Etc | 양성/음성 오류에 대한 개념 | hooni | 2013.04.23 | 23861 |
1140 | Algorithm |
암호 알고리즘 및 프로토콜의 이해..
![]() |
hooni | 2013.04.23 | 18575 |
1139 | Develop |
알고리즘 성능분석
![]() |
hooni | 2014.06.24 | 4260 |
1138 | Develop | 알고리즘 성능 분석 기준 | hooni | 2014.06.24 | 3980 |
1137 | System/OS | 아파치(Apache) 인증사용(htaccess)으로 특정 디렉토리에 암호걸기 | hooni | 2013.04.23 | 14734 |
1136 | Etc |
아이폰의 터치스크린 정확도
![]() |
hooni | 2015.04.01 | 5861 |
1135 | Develop |
아이 훌레시 작업중 ㅋㅋ
![]() |
hooni | 2013.08.09 | 0 |
1134 | Etc | 아두이노 관련 정보.. | hooni | 2013.04.23 | 22999 |
1133 | Etc | 스파이웨어(BHO) 탐지하는 방법.. | hooni | 2013.04.23 | 46553 |
1132 | Algorithm |
스터디 자료, 암호화에 대해서.. 나중에 볼 ppt..
![]() |
hooni | 2013.04.23 | 14897 |
1131 | Etc |
스마트폰 보안 해외 발생 사례~
![]() |
hooni | 2013.04.23 | 26167 |
1130 | Etc | 수리통계학 : 표본공간과 사상-1 | hooni | 2015.04.20 | 2282 |