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 [linux] 임베디드 리눅스 (embedded linux) file hooni 2013.04.23 7387
464 Develop [php] 이미지 회전시키기(gd) hooni 2013.04.23 7372
463 Develop [jsp] 정적/동적(차트생성) 이미지 전달 file hooni 2003.04.23 7351
462 Develop 객체지향 프로그래밍에 대한 개념.. (객체) file hooni 2013.04.23 7345
461 Develop [js] 초간단 현재 사이트 쿠키 확인하는 명령~ hooni 2003.04.23 7343
460 Develop [c]디렉토리 탐색 file hooni 2003.04.23 7341
459 Develop [c] 플러드 필링 (flood filling) 알고리즘.. file hooni 2013.04.23 7338
458 Develop [c++] mfc로 만든 사용자 계정 리스트 출력(EnumUser) 프로그램 예제 file hooni 2013.04.23 7324
457 Develop [pdf] C++ 국제 표준 문서 file hooni 2013.04.23 7322
456 Develop [c] 단기과정[01/08] 과제.. 파스칼 삼각형 file hooni 2003.04.23 7298
455 Develop [c] 신기한 atoi함수(www.game79.net) hooni 2003.04.23 7294
454 Develop [c++] mfc로 만든 부엌 수납 시스템(2D기반 설계) file hooni 2013.04.23 7290
Board Pagination Prev 1 ... 55 56 57 58 59 60 61 62 63 64 ... 98 Next
/ 98