Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3497 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
255 | Develop |
도메인 관련 솔루션 분석할 거.. ㅋㄷ
![]() |
hooni | 2013.04.23 | 7975 |
254 | Develop |
[js] 윤동이가 만든 영어 학습(?) 프로그램
![]() |
hooni | 2013.04.23 | 7974 |
253 | Develop |
[php] 빔 프로젝터 예약 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 7974 |
252 | Develop | [c] 프로세스간의 통신(파이프) | hooni | 2003.04.23 | 7973 |
251 | Develop |
[php] 논문 관리 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 7973 |
250 | Develop | [js] 숫자만 입력하게 하는 자바스크립트 | hooni | 2013.04.23 | 7969 |
249 | Develop |
[c++] 템플릿(Template) 예제 소스..
![]() |
hooni | 2013.04.23 | 7969 |
248 | Develop | 라이브러리에 대한 설명 (static & dynamic library) | hooni | 2013.04.23 | 7966 |
247 | Develop |
[web] 웹 연동 프로그램 모음..
![]() |
hooni | 2013.04.23 | 7961 |
246 | Develop | [c++] template 사용예 | hooni | 2003.04.23 | 7959 |
245 | Develop |
[c++] mfc로 만든 인테리어 수납 시스템(2D기반 설계)
![]() |
hooni | 2013.04.23 | 7959 |
244 | Develop |
[js] 양원님이 공유해 주신 유료(5$란다ㅋ) 자료 ㅋㅋ
![]() |
hooni | 2013.04.23 | 7948 |