Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1104 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
805 | Develop | [php] 쉘에서 실행할 때 인수(파라미터) 받기.. | hooni | 2003.04.23 | 11588 |
804 | Develop | [js] 자바스크립트로 응용프로그램 실행 ㅎㅎ | hooni | 2003.04.23 | 9812 |
803 | Develop | [php] URL/URI 관련 환경변수 | hooni | 2003.04.23 | 9147 |
802 | Develop | [js] 쿠키(cookie)에 대한 설명과 예제.. | hooni | 2003.04.23 | 8321 |
801 | Develop | [js] 스크롤을 포함한 마우스 위치 찾는 코드 | hooni | 2003.04.23 | 8505 |
800 | Develop | [c] pcap을 이용한 패킷 분석 ㅎㅎ | hooni | 2003.04.23 | 10210 |
799 | Develop | [linux] 쉘 스크립트를 이용한 BBS | hooni | 2003.04.23 | 10047 |
798 | Develop | [unix] 쉘 스크립트 예제 모음 | hooni | 2003.04.23 | 14949 |
797 | Develop | [c] 간단한 자료구조(stack, queue, linked list) 구현 소스 6 | hooni | 2003.04.23 | 10109 |
796 | Develop | [c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드 1 | hooni | 2003.04.23 | 11143 |
795 | Develop | [c] 테트리스(Tetris) 게임(도스용) 소스코드 | hooni | 2003.04.23 | 11469 |
794 | Develop | [c] flooding 알고리즘 미로 찾기(도스용) 소스코드 9 | hooni | 2003.04.23 | 12501 |