Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
Views 1102 Comment 0
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 parseInt
in that case, which may be as good as anything.
[출처] https://stackoverflow.com/questions/4460595/jquery-filter-numbers-of-a-string
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
1149 | Etc | IPR 특허 관련 | hooni | 2015.04.28 | 0 |
1148 | System/OS | iptime 공유기 해킹 기술문서 4 | hooni | 2015.01.01 | 1941 |
1147 | Etc | ISMS 인증기준 – 정보보호대책 (시스템개발보안) | hooni | 2016.12.01 | 1299 |
1146 | Etc | IT감사 기법 시험 | hooni | 2017.06.14 | 1416 |
1145 | Develop | JSON, BSON 변환 | 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 | hooni | 2017.03.15 | 8091 |
1141 | Develop | macOS에 node, npm 설치하기 (homebrew) | hooni | 2021.11.06 | 1139 |
1140 | System/OS | Mac에서 Node.js 설치하기 | hooni | 2018.09.28 | 4185 |
1139 | System/OS | NAT와 DHCP에 대한 간단한 설명 | hooni | 2013.04.23 | 18328 |
1138 | Algorithm | OCB5 Injection 앗싸뵹! ㅋㅋ | hooni | 2014.07.01 | 796 |