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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
207 | Develop | [c] SetTimer() & KillTimer() & 일회용 Timer | hooni | 2013.04.23 | 10797 |
206 | Develop |
[c] selec()를 이용한 입출력 다중화
![]() |
hooni | 2013.04.23 | 9295 |
205 | Develop | [c] scanf(), printf() 포맷의 형변환 | hooni | 2003.04.23 | 12520 |
204 | Develop |
[c] RSA 암호화 구현(gmp 라이브러리 활용)
![]() |
hooni | 2016.10.03 | 2744 |
203 | Develop | [c] pcap을 이용한 패킷 분석 ㅎㅎ | hooni | 2003.04.23 | 11570 |
202 | Develop |
[c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 8057 |
201 | Develop |
[c] openssl 샘플코드.. 어려움 ㅠㅠ
![]() |
hooni | 2013.04.23 | 7760 |
200 | Develop | [c] OpenGL 직사각형(2D) 크기 확대/축소 | hooni | 2003.04.23 | 10088 |
199 | Develop | [c] OpenGL 임시로 여기 올림.. | hooni | 2003.04.23 | 11173 |
198 | Develop | [c] OpenGL 시어핀스키 가스킷(p.73 - 첫시간) | hooni | 2003.04.23 | 9794 |
197 | Develop | [c] OpenGL 색 입방체의 회전(입체) | hooni | 2003.04.23 | 8977 |
196 | Develop | [c] OpenGL 마우스 이벤트 | hooni | 2003.04.23 | 10023 |