Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3459 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
421 | Develop | [c] 연산자 우선순위.. ㅋㅋ | hooni | 2013.04.23 | 8305 |
420 | Develop |
[c] 지폰(gphone) 소스.. 수정(암호화)
![]() |
hooni | 2013.04.23 | 8291 |
419 | Develop | [c] 신기한 atoi함수(www.game79.net) | hooni | 2003.04.23 | 8283 |
418 | Develop | [asp] 기본 문법과 제어문 | hooni | 2013.04.23 | 8282 |
417 | Develop |
[c] 로또(Lotto) 번호 생성기
![]() |
hooni | 2013.04.23 | 8279 |
416 | Develop | [linux] crond 사용법.. ㅋㅋ | hooni | 2013.04.23 | 8270 |
415 | Develop | [js] php의 number_format() 함수와 같은.. ㅋㅋ | hooni | 2013.04.23 | 8266 |
414 | Develop |
[js] 한글문서로 된 259가지 자바스크립트 예제파일
![]() |
hooni | 2013.04.23 | 8263 |
413 | Develop |
[pdf] 포인터 문법 정리 (C pointer)
![]() |
hooni | 2013.04.23 | 8262 |
412 | Develop |
[linux] 임베디드 리눅스 (embedded linux)
![]() |
hooni | 2013.04.23 | 8262 |
411 | Develop |
[c] 게임 AI FSM 테스트 샘플 소스.. 꽤 괜찮은 소스..
![]() |
hooni | 2013.04.23 | 8248 |
410 | Develop |
[c] 문자열 라이브러리 최신버전
![]() |
hooni | 2003.04.23 | 8247 |