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
-
[ppt] iOS 플라랩#02(2015.03.19) 발표 자료
-
맥에서 포트 확인하고 닫기 (mac)
-
수리통계학 : 표본공간과 사상-1
-
[ios] iOS 8 개발자가 우선 알아야 할 3가지
-
[js] 좋은 강연자료 & UI 자료
-
[virtualbox] VirtualBox에 Ubuntu 설치하기
-
[ppt] Equation Solving 발표 자료 (@AjaxUI랩 밋업데이 2012.02.28)
-
삼성페이(Samsung Pay) 구조
-
[android] 딜레이를 구현하기 위한 꼼수
-
콘솔에서 패스워드 걸린 zip 압축하는 명령
-
[ubuntu] 우분투 18.04에 PHP5 설치하기
-
[펌] 마이크로서비스, 모노리포, SRE, ... 덮어놓고 구글 따라하면 안 되는 기술들