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
1149 Etc IPR 특허 관련 secret hooni 2015.04.28 0
1148 System/OS iptime 공유기 해킹 기술문서 4 file hooni 2015.01.01 1941
1147 Etc ISMS 인증기준 – 정보보호대책 (시스템개발보안) file hooni 2016.12.01 1299
1146 Etc IT감사 기법 시험 file hooni 2017.06.14 1416
1145 Develop JSON, BSON 변환 file hooni 2013.04.23 11814
1144 Develop Laravel 5 Failed opening required bootstrap/../vendor/autoload.php hooni 2018.01.24 1652
1143 System/OS Mac OS X - Apache+PHP+MySQL 환경 서버 hooni 2013.04.25 31627
1142 Develop Mac OS 에 Jenkins 설치하기 (Homebrew) 2 file hooni 2017.03.15 8091
1141 Develop macOS에 node, npm 설치하기 (homebrew) file hooni 2021.11.06 1139
1140 System/OS Mac에서 Node.js 설치하기 file hooni 2018.09.28 4185
1139 System/OS NAT와 DHCP에 대한 간단한 설명 hooni 2013.04.23 18328
1138 Algorithm OCB5 Injection 앗싸뵹! ㅋㅋ file hooni 2014.07.01 796
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98