Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1354 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
253 | Develop | [java] Sieve of Eratosthenes (에라토스테네스의 체) | hooni | 2013.04.23 | 9348 |
252 | Develop |
[c] 유닉스 프로그램에서 인수처리 해주는 getopt() 함수
![]() |
hooni | 2013.04.23 | 8090 |
251 | Develop |
[c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 6914 |
250 | Develop |
[php] 무조건 다운로드 받도록 header 세팅
![]() |
hooni | 2013.04.23 | 7421 |
249 | Develop |
[php] 자바스크립트 개판 만들기..
![]() |
hooni | 2013.04.23 | 7684 |
248 | Develop |
[js] 자바스크립트로 만든 게임
![]() |
hooni | 2013.04.23 | 8412 |
247 | Develop |
[js] 윤동이가 만든 영어 학습(?) 프로그램
![]() |
hooni | 2013.04.23 | 6478 |
246 | Develop |
[js] 밀리터리 프로그램(전역일 계산)
7 ![]() |
hooni | 2013.04.23 | 8931 |
245 | Develop |
[js] 빈도우즈(bindows96)
![]() |
hooni | 2013.04.23 | 7395 |
244 | Develop |
[js] 후리자(영규) 스타일들..
![]() |
hooni | 2013.04.23 | 7179 |
243 | Develop |
[js] 여러가지 트리(tree) 모음.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 7135 |
242 | Develop | [js] IE에서 인쇄 설정 팁 | hooni | 2013.04.23 | 10921 |