Contents

?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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
No. Category Subject Author Date Views
1117 System/OS [dos] 노트북 백업 스크립트 xcopy 명령 예제 hooni 2003.04.23 41797
1116 System/OS [mac] Mac에서 Mac으로 원격제어하기 (맥에서 맥으로) file hooni 2013.10.08 41511
1115 PPT [android][ios] 알림(Notification) 기능에 대한 원리와 구현 방안 (APNS포함) file hooni 2013.04.23 41489
1114 Develop [android] 개발 환경 세팅 따라하기 ㅋㅋ file hooni 2013.04.23 41198
1113 Develop [ios] iOS 4.0 beta 에서 3.1.3으로 다운그레이드 하는 법 file hooni 2013.04.23 41097
1112 System/OS CentOS 6.5 USB 설치 6 file hooni 2013.12.18 39989
1111 Develop [js] jQuery 충돌 회피 hooni 2013.12.17 39469
1110 System/OS [linux] 처음 설치부터 APM 설치까지 (업데이트 할 것) hooni 2013.04.23 39463
1109 System/OS 맥에서 파일공유 (윈도우,맥) file hooni 2013.04.25 38349
1108 Develop [ios] iOS 6.0 이상 회전 하기 (이전 버전과 비교 변경 부분) file hooni 2014.01.27 38258
1107 Develop [js] jQuery 치트 시트 hooni 2013.12.18 37215
1106 Develop [php] 몽이가 준 ajax 채팅 소스 ㅋㅋ file hooni 2013.04.23 37132
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 99 Next
/ 99