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
465 Develop [c] 네트워크 관련 프로그래밍 (포트스캔 탐지 샘플) file hooni 2013.04.23 7223
464 System/OS [linux] 리눅스 파일시스템과 디렉토리 설명 hooni 2013.04.23 26943
463 System/OS [linux] 리눅스, 유닉스 CPU 이용률 확인.. hooni 2013.04.23 23866
462 System/OS [linux] 리눅스,유닉스 /proc/stat 파일 보는 법 hooni 2013.04.23 18033
461 Develop [c] 프로세스 검사하기 hooni 2013.04.23 8052
460 Develop [asp] 폼메일 예제와 메일 포워딩 프로그램 file hooni 2013.04.23 7159
459 Develop [asp] 폼 메일 소스 file hooni 2013.04.23 7403
458 Develop [php] php+db 연동(odbc, mssql, mysql, sybase) 3 hooni 2013.04.23 8577
457 Develop 프로그램 문서 관리 (Doxygen) hooni 2013.04.23 16446
456 Develop 프로그래밍 소스 관련 사이트.. hooni 2013.04.23 16533
455 Develop 도메인 관련 솔루션 분석할 거.. ㅋㄷ file hooni 2013.04.23 7062
454 Develop [js] 수명체크 프로그램 ㅋㅋ file hooni 2013.04.23 6907
Board Pagination Prev 1 ... 55 56 57 58 59 60 61 62 63 64 ... 98 Next
/ 98