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