Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1354 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
49 | Develop | [android] 만화 어플 소스코드 | hooni | 2013.04.23 | 92923 |
48 | Develop | [android] 레이아웃 사이즈 변경 (동적; programmatically) | hooni | 2016.11.07 | 1620 |
47 | Develop | [android] 딜레이를 구현하기 위한 꼼수 | hooni | 2016.11.24 | 1081 |
46 | Develop | [android] 디바이스(시뮬레이터) hosts 파일 수정하기 | hooni | 2013.04.23 | 31130 |
45 | Develop | [android] 단일 Thread 환경의 안드로이드에서 Handler를 사용 | hooni | 2013.04.23 | 26576 |
44 | Develop | [android] 개발 환경 세팅 따라하기 ㅋㅋ | hooni | 2013.04.23 | 40462 |
43 | Develop | [android] 간단한 SQLIite 예제 | hooni | 2017.06.14 | 1472 |
42 | Develop | [android] 가속도 센서를 이용한 흔듦(Shake) 감지 | hooni | 2014.11.04 | 2005 |
41 | Develop | [android] [번역] 안드로이드 Android Cloud to Device Messaging(C2DM) | hooni | 2013.04.23 | 20482 |
40 | Develop | [android] SurfaceView를 이용한 애니메이션 ㅎㅎ | hooni | 2013.04.23 | 57775 |
39 | Develop | [android] SQLiteOpenHelper를 이용한 DBManager | hooni | 2017.06.14 | 2190 |
38 | Develop | [android] N-Puzzle 게임 | hooni | 2015.07.09 | 960 |