Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3497 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1153 | Etc |
IoT가 만드는 미래와 플랫폼 경쟁력
![]() |
hooni | 2014.09.23 | 0 |
1152 | Etc |
IPR 특허 관련
![]() |
hooni | 2015.04.28 | 0 |
1151 | System/OS |
iptime 공유기 해킹 기술문서
4 ![]() |
hooni | 2015.01.01 | 3623 |
1150 | Etc |
ISMS 인증기준 – 정보보호대책 (시스템개발보안)
![]() |
hooni | 2016.12.01 | 3715 |
1149 | Etc |
IT감사 기법 시험
![]() |
hooni | 2017.06.14 | 3790 |
1148 | Develop |
JSON, BSON 변환
![]() |
hooni | 2013.04.23 | 13134 |
1147 | Develop | Laravel 5 Failed opening required bootstrap/../vendor/autoload.php | hooni | 2018.01.24 | 6121 |
1146 | System/OS | Mac OS X - Apache+PHP+MySQL 환경 서버 | hooni | 2013.04.25 | 34805 |
1145 | Develop |
Mac OS 에 Jenkins 설치하기 (Homebrew)
2 ![]() |
hooni | 2017.03.15 | 13256 |
1144 | Develop |
macOS에 node, npm 설치하기 (homebrew)
![]() |
hooni | 2021.11.06 | 4554 |
1143 | System/OS |
Mac에서 Node.js 설치하기
![]() |
hooni | 2018.09.28 | 5978 |
1142 | System/OS | NAT와 DHCP에 대한 간단한 설명 | hooni | 2013.04.23 | 19152 |