Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1340 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1041 | PPT |
[ppt] 보안경제학 발표자료
![]() |
hooni | 2016.11.11 | 5 |
1040 | Develop | [Android Error] The number of method references in a .dex file cannot exceed 64K | hooni | 2016.11.10 | 880 |
1039 | Develop | [android] 레이아웃 사이즈 변경 (동적; programmatically) | hooni | 2016.11.07 | 1597 |
1038 | Develop | [android] 초간단 얼럿 (AlertDialog) | hooni | 2016.10.21 | 928 |
1037 | Develop | [android] dp, px 서로 변환 | hooni | 2016.10.21 | 3493 |
1036 | Develop |
[matlab] ZigZag-Scanning (2-D Array)
![]() |
hooni | 2016.10.15 | 2097 |
1035 | System/OS |
[mac] OS X 엘 캐피탄에서 Soudflower 사용하기
2 ![]() |
hooni | 2016.10.03 | 1157 |
1034 | System/OS |
[mac] Mac OS에서 재생되는 사운드를 녹음하는 방법
![]() |
hooni | 2016.10.03 | 1727 |
1033 | Develop |
[matlab] 정보은닉 스테가노그래피(Steganography) 수업
![]() |
hooni | 2016.10.03 | 779 |
1032 | Develop |
[c] RSA 암호화 구현(gmp 라이브러리 활용)
![]() |
hooni | 2016.10.03 | 1000 |
1031 | Develop | [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 | hooni | 2016.10.03 | 1427 |
1030 | Develop | [c] 셀프 넘버(Self Number) 구하기 1 | hooni | 2016.09.09 | 2370 |