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
153 System/OS [sql] 중복데이터 삭제 쿼리 hooni 2013.04.23 14813
152 Database [sql] 쿼리로 문자열 검색해서 일괄 치환하기 hooni 2014.02.13 10065
151 Database [sql] 한눈에 보이는 Join file hooni 2014.02.19 8549
150 System/OS [svn] Can't convert string from native encoding to 'UTF-8' 메시지가 나오는 경우 hooni 2014.12.18 1163
149 System/OS [svn] SVN trunk 변경사항 되돌리기 (SVN Rollback) hooni 2014.11.27 1714
148 Etc [svn] 콘솔에서 svn 사용시 레티나용 이미지 add 안될 때.. hooni 2013.09.25 37645
147 System/OS [svn] 하나의 SVN에서 멀티 저장소 (One svnserve, multiple repositories) hooni 2015.01.02 1794
146 Develop [swift] NotificationCenter 간단 예제 file hooni 2021.01.27 8340
145 Develop [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 file hooni 2021.01.29 1598
144 Develop [swift] UIView에서 subview 찾기 hooni 2022.12.09 2059
143 Develop [swift] 실행시간 측정하기 hooni 2021.09.14 844
142 System/OS [switch] 시스코 스위치 관리자 암호 초기화 방법 hooni 2013.04.23 17290
Board Pagination Prev 1 ... 81 82 83 84 85 86 87 88 89 90 ... 98 Next
/ 98