Contents

?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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 parseIntin that case, which may be as good as anything.

[출처] https://stackoverflow.com/questions/4460595/jquery-filter-numbers-of-a-string


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
649 Develop [js] 사라지는 브라우저 hooni 2003.04.23 6857
648 Develop [js] 빈도우즈(bindows96) file hooni 2013.04.23 7368
647 Develop [js] 비만 지수 측정(BMI) ㅎㅎ file hooni 2013.04.23 7610
646 Develop [js] 부모창에서 자식창으로 문자열 전달.. file hooni 2013.04.23 7448
645 Develop [js] 밀리터리 프로그램(전역일 계산) 7 file hooni 2013.04.23 8910
» Develop [js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식) hooni 2017.12.14 1100
643 Develop [js] 모바일웹에서 이미지 저장하는거 (context menu) 막기 hooni 2013.04.23 26360
642 Develop [js] 모바일 스크롤 방지(해제) hooni 2015.04.14 1588
641 Develop [js] 동적(innerHTML)으로 자바스크립트 실행하기.. 2 file hooni 2013.04.23 18199
640 Develop [js] 네이버에서 그림 퍼올 때.. URL Encoding 관련ㅋㅋ hooni 2013.04.23 7212
639 Develop [js] 네이버, 다음의 플레이어 스킨 file hooni 2013.04.23 6942
638 Develop [js] 객체 머지.. hooni 2013.12.17 8961
Board Pagination Prev 1 ... 12 13 14 15 16 17 18 19 20 21 ... 71 Next
/ 71