Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1094 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1137 | System/OS | [linux] 웹로그분석기(webalizer) 설치 & 팁 | hooni | 2003.04.23 | 14882 |
1136 | System/OS | [linux] 데스크탑환경(GNOME/KDE) 바꾸기.. | hooni | 2003.04.23 | 12101 |
1135 | System/OS | [linux] 센드메일 동적릴레이 설치 | hooni | 2003.04.23 | 15228 |
1134 | System/OS | HTTP 프로토콜 (브라우저와 웹서버 간의 통신) | hooni | 2003.04.23 | 48250 |
1133 | Database | [mysql] DB->Text, Text->DB 변환 | hooni | 2003.04.23 | 12129 |
1132 | System/OS | [windows] 패스워드를 잊어먹었을때.. | hooni | 2003.04.23 | 17294 |
1131 | System/OS | [bios] 시스템 부팅 도중 발생하는 비프음 | hooni | 2003.04.23 | 18158 |
1130 | System/OS | [unix] SUN Solaris 싱글모드.. ㅡ,.ㅡ; | hooni | 2003.04.23 | 11991 |
1129 | System/OS | [linux] ProFTPD 타임아웃 설정 | hooni | 2003.04.23 | 12851 |
1128 | Develop | [css] 스크롤바 안생기게 | hooni | 2003.04.23 | 9886 |
1127 | System/OS | [unix] 유닉스 csh에서 환경변수 등록 | hooni | 2003.04.23 | 11694 |
1126 | System/OS | [linux] 쉘 스크립트 (Shell Script) | hooni | 2003.04.23 | 12064 |