Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1341 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1029 | Develop | [c++] mfc 파일 한줄씩 읽기.. ㅋㅋ | hooni | 2013.04.23 | 28590 |
1028 | Develop |
[c++] MFC로 만든 디렉토리/파일 파인더
![]() |
hooni | 2013.04.23 | 9349 |
1027 | Develop |
[c++] mfc로 만든 부엌 수납 시스템(2D기반 설계)
![]() |
hooni | 2013.04.23 | 7283 |
1026 | Develop |
[c++] mfc로 만든 사용자 계정 리스트 출력(EnumUser) 프로그램 예제
![]() |
hooni | 2013.04.23 | 7312 |
1025 | Develop |
[c++] mfc로 만든 월플렉스 멀티 수납 시스템(2D기반 설계)
![]() |
hooni | 2013.04.23 | 7421 |
1024 | Develop |
[c++] mfc로 만든 인테리어 수납 시스템(2D기반 설계)
![]() |
hooni | 2013.04.23 | 7267 |
1023 | Develop |
[c++] mfc로 만든 현재 디렉토리 읽어오기/세팅하기 (GetCurrentDirectory/SetCurrentDirectory)
![]() |
hooni | 2013.04.23 | 8499 |
1022 | Develop | [c++] mfc에서 윈도우 항상 위 속성 주기.. | hooni | 2013.04.23 | 11340 |
1021 | Develop |
[c++] mfc이용한 트레이아이콘(TrayIcon) 클래스 예제 프로젝트
![]() |
hooni | 2013.04.23 | 9267 |
1020 | Develop | [c++] namespace 사용 예 | hooni | 2003.04.23 | 8698 |
1019 | Develop | [c++] p.118 확인학습 5번 | hooni | 2003.04.23 | 10763 |
1018 | Develop | [c++] p.47 연습문제 3번 | hooni | 2003.04.23 | 10141 |