Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1093 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1149 | Etc | 영어의 12 시제 (The twelve tenses of English) | hooni | 2013.07.12 | 15699 |
1148 | Etc | 영어공부에 도움될만한 사이트 모음 | hooni | 2013.05.14 | 22628 |
1147 | Etc | 영어. 외우면 도움되는 필수영어회화 표현 | hooni | 2013.09.09 | 20923 |
1146 | Etc | 영어. 불규칙 동사 정리 | hooni | 2017.10.04 | 3480 |
1145 | Etc | 영어. 반드시 외워야 할 영어 숙어 2 | hooni | 2016.07.07 | 6313 |
1144 | Etc | 영어. 반드시 외워야 할 문장 패턴 100개 | hooni | 2023.06.08 | 902 |
1143 | Etc | 영어. 반드시 외워야 할 단어 | hooni | 2016.07.07 | 1949 |
1142 | Etc | 영어 아주 쉬운 영작문 강의 01~60 | hooni | 2013.06.25 | 0 |
1141 | Etc | 영어 관련 토렌트 | hooni | 2013.06.25 | 0 |
1140 | Etc | 여러 대학 및 권위있는 기관 강좌 모음 ㅋㅋ | hooni | 2013.06.17 | 15115 |
1139 | Etc | 여기저기서 모은 VoIP(인터넷전화) 자료들~ | hooni | 2013.04.23 | 15966 |
1138 | Etc | 엑셀 함수 총 정리 ㅎㅎ | hooni | 2013.06.05 | 24458 |