Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3485 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
759 | Develop | [js] 키보드 아스키코드(ASCII) 코드보기 | hooni | 2003.04.23 | 33411 |
758 | Develop | [js] 이벤트 핸들러(Event Handlers) | hooni | 2003.04.23 | 8017 |
757 | Develop | [js] 사라지는 브라우저 | hooni | 2003.04.23 | 8419 |
756 | Develop | [c] OpenGL 마우스 이벤트 | hooni | 2003.04.23 | 10023 |
755 | Develop | [js] 점점 커지는 새창.. | hooni | 2003.04.23 | 7816 |
754 | Develop |
[c][java] 소켓 프로그래밍(채팅 서버 C, 클라이언트 Java)
![]() |
hooni | 2003.04.23 | 8403 |
753 | Develop | [c] 신기한 atoi함수(www.game79.net) | hooni | 2003.04.23 | 8283 |
752 | Develop | [c] OpenGL 색 입방체의 회전(입체) | hooni | 2003.04.23 | 8977 |
751 | Develop |
[php] 마시마로 캐릭터 방명록
![]() |
hooni | 2003.04.23 | 9285 |
750 | Develop |
[c] 시간 계산 하는 프로그램 소스코드
![]() |
hooni | 2003.04.23 | 7892 |
749 | Develop | [linux] 프로세스 관련 시스템콜 | hooni | 2003.04.23 | 9251 |
748 | Develop | [c] 문자열 처리 관련 함수들 설명 | hooni | 2003.04.23 | 9187 |