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
번호 분류 제목 글쓴이 날짜 조회 수
721 Etc [flash] 자동차 엔진의 원리 (4행정 사이클 그림) file hooni 2013.04.23 22164
720 Etc [flash] 페이지 이동 (액션스크립트) file hooni 2013.04.23 17241
719 Develop [git] 쉬운 버전관리 Git 설명 hooni 2015.08.18 2276
718 Develop [html] HTML5 튜토리얼 링크 ㅋㅋ hooni 2013.04.23 14039
717 Develop [html] SVG(Scalable Vector Graphics) 간단 정리 hooni 2014.02.13 11337
716 Develop [html] 메타태그 사용예.. 은지나 바라~ hooni 2003.04.23 8413
715 Develop [html] 캐쉬된 웹페이지 사용하지 않도록 하는 방법 hooni 2003.04.23 14451
714 Etc [htm] DOM에 대해 ㅎㅎ file hooni 2003.04.23 15950
713 Develop [ios] UIView 계층구조 hooni 2015.01.03 2333
712 Develop [ios] @property의 속성 (strong, weak, copy) 사용 경우 hooni 2014.08.08 2819
711 Develop [ios] AES256 알고리즘을 이용해 데이터 암호화/복호화 방법 file hooni 2015.07.21 5467
710 Develop [ios] APNS 샘플 코드.. secret hooni 2013.06.27 0
Board Pagination Prev 1 ... 34 35 36 37 38 39 40 41 42 43 ... 99 Next
/ 99