Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1094 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1173 | System/OS | 해커스랩 깨기.. 후후.. ㅋㅋ | hooni | 2013.04.23 | 18411 |
1172 | Etc | 플라스터(Plaster) 수업 내용 | hooni | 2016.05.24 | 0 |
1171 | Develop | 프로그램 문서 관리 (Doxygen) | hooni | 2013.04.23 | 16385 |
1170 | Develop | 프로그래밍에서 foo, bar 함수의 유래 | hooni | 2013.06.25 | 21244 |
1169 | Develop | 프로그래밍 소스 관련 사이트.. | hooni | 2013.04.23 | 16485 |
1168 | Develop | 페이팔에서 돈 찾기 (Paypal withdraw) | hooni | 2014.02.20 | 10956 |
1167 | Etc | 티스토리 테이블 html,css 구문 | hooni | 2013.11.03 | 15944 |
1166 | System/OS | 콘솔에서 패스워드 걸린 zip 압축하는 명령 | hooni | 2018.03.02 | 929 |
1165 | System/OS | 컴파일러 수업 자료(교재 : 컴파일러 입문) | hooni | 2003.04.23 | 21966 |
1164 | Develop | 캘리포니아 운전면허 족보 | hooni | 2017.06.12 | 726 |
1163 | Etc | 캘리포니아 운전면허 문제 | hooni | 2017.07.22 | 968 |
1162 | Develop | 최근 논문 자료 (2011/01/03, 만현형한테 보낸거..) | hooni | 2013.04.23 | 10366 |