Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1295 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
205 | Develop |
[c] 다중연결 서버 만들기 #2 - select() 사용
![]() |
hooni | 2013.04.23 | 9371 |
204 | Develop |
[c] 다중연결 서버 만들기 #1 - fork() 사용
![]() |
hooni | 2013.04.23 | 12941 |
203 | Develop |
[c] 도메인 소켓(Unix Domain Socket) UDP
![]() |
hooni | 2013.04.23 | 9304 |
202 | Develop |
[c] 간단한 소켓 프로그래밍 샘플
![]() |
hooni | 2013.04.23 | 8176 |
201 | Develop |
[c] 패킷 유량/프로토콜 통계 모니터링..
![]() |
hooni | 2013.04.23 | 8391 |
200 | Develop | [c] 달팽이 배열? 인지 먼지.. ㅋㅋ | hooni | 2013.04.23 | 7143 |
199 | Develop |
[java] RGB 색상 조절 버튼.. 스윙(swing)
![]() |
hooni | 2013.04.23 | 7856 |
198 | Develop |
[java] 채팅창 처럼2.. swing..
![]() |
hooni | 2013.04.23 | 6437 |
197 | Develop |
[java] 채팅창 처럼.. swing..
![]() |
hooni | 2013.04.23 | 8789 |
196 | Develop |
[java] 마우스 버튼 테스트.. swing..
![]() |
hooni | 2013.04.23 | 7902 |
195 | Develop |
[java] 메모패드.. 스윙(swing)으로..
![]() |
hooni | 2013.04.23 | 8478 |
194 | Develop |
[java] 스윙(swing)버튼 테스트 ㅋㅋ
![]() |
hooni | 2013.04.23 | 9439 |