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
169 Develop [ios] How To Use UIScrollView to Scroll and Zoom Content (Using Objective-C) file hooni 2016.03.23 4245
168 Develop [ios] How To Use UIScrollView to Scroll and Zoom Content (Using Swift) file hooni 2016.03.23 11605
167 Develop [ios] Did UIScrollView End Scrolling? hooni 2016.04.19 8318
166 Develop [io] Apple Watch, Today Extension 앱ID 설정 hooni 2016.04.20 4161
165 Develop XE Core 1.8.18 본문 작성시 태그(html) 사라지는 버그 file hooni 2016.04.21 2100
164 PPT [ppt] 전자금융보안론 발표/설치 자료 file hooni 2016.05.03 2954
163 Develop [c#] 전자금융보안론 발표/설치 자료(툴바 소스코드) secret hooni 2016.05.07 0
162 Develop [ios] UUID 생성 + Key Chain 연동 file hooni 2016.05.13 10177
161 Develop [ios] 기본 네비게이션바의 타이틀, back버튼 위치와 속성 변경 file hooni 2016.05.16 5167
160 Etc 플라스터(Plaster) 수업 내용 secret hooni 2016.05.24 0
159 Develop [ios] 웹뷰 history.back() ㅋㄷ file hooni 2016.06.27 5667
158 Develop [ios][swift] 초간단 TableView 샘플 file hooni 2016.06.27 5215
157 Develop [ios][swift] 초간단 To-do Memo file hooni 2016.06.27 11035
156 Develop [ios][swift] 초간단 카달로그 앱 (Catalog App) file hooni 2016.06.27 14307
155 Etc 영어. 반드시 외워야 할 단어 file hooni 2016.07.07 3994
154 Etc 영어. 반드시 외워야 할 영어 숙어 2 file hooni 2016.07.07 8101
Board Pagination Prev 1 ... 62 63 64 65 66 ... 74 Next
/ 74