Views 3459 Votes 0 Comment 0
?

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
59 Develop [switch] 시스코 카탈리스트(Cisco Catalyst) 2950 미러링 설정 hooni 2013.04.23 12066
58 Develop [ubuntu] 우분투 18.04에 PHP5 설치하기 hooni 2020.11.14 3266
57 Develop [unix] Java 애플릿용 HTML 자동 생성 hooni 2014.02.19 9288
56 Develop [unix] 날짜 관련 쉘 명령어 (특정일 또는 +-시간, 날짜 계산된 값) hooni 2013.04.23 15854
55 Develop [unix] 로그파일 정리 쉘스크립트 hooni 2014.02.19 16120
54 Develop [unix] 쉘 스크립트 예제 모음 hooni 2003.04.23 17975
53 Develop [unix] 유닉스 명령에 메타문자 사용 hooni 2014.02.19 12854
52 Develop [vbs] CD롬 뱉는 스크립트.. hooni 2003.04.23 12670
51 Develop [vb] 64bit RSA 프로그램 소스 ㅋㅋ file hooni 2013.04.23 9200
50 Develop [vb] 문자열에서 태그 제거함수 (Visual Basic) file hooni 2013.04.23 25597
49 Develop [vb] 비주얼 베이직 131페이지 hooni 2003.04.23 65228
48 Develop [vb] 비주얼 베이직 141페이지 hooni 2003.04.23 65835
47 Develop [vb] 비주얼 베이직 173페이지 hooni 2003.04.23 62144
46 Develop [vb] 비주얼 베이직 205페이지 hooni 2003.04.23 63360
45 Develop [vb] 비주얼 베이직 순위 정렬 루틴 hooni 2003.04.23 66296
44 Develop [vb] 비주얼 베이직 자격증용 ㅎㅎ hooni 2003.04.23 68519
Board Pagination Prev 1 ... 48 49 50 51 52 53 Next
/ 53