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
81 Develop [android] 개발 환경 세팅 따라하기 ㅋㅋ file hooni 2013.04.23 40456
80 Develop [android] 간단한 SQLIite 예제 hooni 2017.06.14 1454
79 Develop [android] 가속도 센서를 이용한 흔듦(Shake) 감지 file hooni 2014.11.04 1997
78 Develop [android] [번역] 안드로이드 Android Cloud to Device Messaging(C2DM) hooni 2013.04.23 20477
77 PPT [android] XML파서(XMLParser)의 종류와 성능 비교에 대한 발표 자료 file hooni 2013.04.23 75705
76 Develop [android] SurfaceView를 이용한 애니메이션 ㅎㅎ file hooni 2013.04.23 57759
75 Develop [android] SQLiteOpenHelper를 이용한 DBManager hooni 2017.06.14 2167
74 Develop [android] N-Puzzle 게임 file hooni 2015.07.09 953
73 Develop [android] ListView+ArrayAdapter 테스트 hooni 2013.04.23 43946
72 Develop [android] keytool을 사용하여 키스토어 생성 hooni 2013.04.23 69571
71 Develop [android] How can I place app icon on launcher home screen? hooni 2016.11.15 1401
70 Develop [android] GCM 사용하기 1 (GCM 서비스 신청하기) file hooni 2013.07.06 51419
Board Pagination Prev 1 ... 87 88 89 90 91 92 93 94 95 96 ... 98 Next
/ 98