Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3536 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
831 | Develop | 알고리즘 성능 분석 기준 | hooni | 2014.06.24 | 3992 |
830 | Develop |
아이 훌레시 작업중 ㅋㅋ
![]() |
hooni | 2013.08.09 | 0 |
829 | Develop | 서기의 PHP 동영상 강의(싱싱해) | hooni | 2013.05.15 | 31898 |
828 | Develop |
사이버보안실무 수업 메모
![]() |
hooni | 2017.03.23 | 0 |
827 | Develop |
사이버보안실무 발표자료 (2017.06.08)
![]() |
hooni | 2017.06.05 | 9941 |
826 | Develop |
베지어 곡선(Bézier curve) 알고리즘(spline 곡선)
3 ![]() |
hooni | 2013.04.23 | 35266 |
825 | Develop |
밸런싱 로봇.. 최종.. (관련 논문도 첨부) ㅋㅋ
![]() |
hooni | 2013.04.23 | 24158 |
824 | Develop |
모터에 대한 pid 제어.. ㅎㅎ
![]() |
hooni | 2013.04.23 | 19730 |
823 | Develop |
링크들 보고 지울 내용
![]() |
hooni | 2019.11.21 | 0 |
822 | Develop |
리팩토링 계획안
![]() |
hooni | 2017.05.15 | 2357 |
821 | Develop |
레고 마인드스톰 NXT 수도쿠, 큐브 소스코드..
20 ![]() |
hooni | 2013.04.23 | 83100 |
820 | Develop |
레고 NXT 마인드스톰 밸런싱 로봇 ㅎㅎ
![]() |
hooni | 2013.04.23 | 58764 |