Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1294 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
49 | Develop | [jsp][php] 간단한 강좌 자료.. | hooni | 2003.04.23 | 8126 |
48 | Develop | [c] flooding 알고리즘 미로 찾기(도스용) 소스코드 9 | hooni | 2003.04.23 | 12560 |
47 | Develop | [c] 테트리스(Tetris) 게임(도스용) 소스코드 | hooni | 2003.04.23 | 11497 |
46 | Develop | [c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드 1 | hooni | 2003.04.23 | 11170 |
45 | Develop | [c] 간단한 자료구조(stack, queue, linked list) 구현 소스 6 | hooni | 2003.04.23 | 10139 |
44 | Develop | [unix] 쉘 스크립트 예제 모음 | hooni | 2003.04.23 | 14992 |
43 | Develop | [linux] 쉘 스크립트를 이용한 BBS | hooni | 2003.04.23 | 10070 |
42 | Develop | [c] pcap을 이용한 패킷 분석 ㅎㅎ | hooni | 2003.04.23 | 10231 |
41 | Develop | [js] 스크롤을 포함한 마우스 위치 찾는 코드 | hooni | 2003.04.23 | 8539 |
40 | Develop | [js] 쿠키(cookie)에 대한 설명과 예제.. | hooni | 2003.04.23 | 8341 |
39 | Develop | [php] URL/URI 관련 환경변수 | hooni | 2003.04.23 | 9198 |
38 | Develop | [js] 자바스크립트로 응용프로그램 실행 ㅎㅎ | hooni | 2003.04.23 | 9836 |