조회 수 1350 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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 parseIntin that case, which may be as good as anything.

[출처] https://stackoverflow.com/questions/4460595/jquery-filter-numbers-of-a-string

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
165 Develop [php] 한글 문자열 자르기 (utf-8) hooni 2015.11.10 1453
164 PPT [ppt] 전자금융보안론 발표/설치 자료 file hooni 2016.05.03 1446
163 Develop [js] URL 파싱하기 (jQuery 안쓰고) hooni 2017.12.14 1438
162 Develop [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 hooni 2016.10.03 1437
161 Etc 원어민이 매일 쓰는 일상표현 150개 file hooni 2023.09.17 1435
160 Develop [ios] GPS 이용 상태 확인 hooni 2015.04.27 1414
159 System/OS [linux] yum 업데이트 시 커널 제외하기 hooni 2014.09.11 1407
158 Develop [vim] vim 명령으로  문자 제거하기 (remove 65279 bomb) hooni 2021.02.03 1404
157 Develop [android] How can I place app icon on launcher home screen? hooni 2016.11.15 1404
156 System/OS [linux] iptables 초간단 세팅 스크립트 hooni 2017.09.26 1398
155 Develop [ios] 동영상 플레이어 샘플 (for PIP Player) file hooni 2017.03.15 1394
154 PPT [ppt] Macro for board game 발표자료 (@Team Study 2013.01.18) 1 file hooni 2015.07.22 1374
153 Etc 영어. 반드시 외워야 할 문장 패턴 100개 file hooni 2023.06.08 1373
152 Database [mysql] ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. hooni 2017.12.15 1371
151 Develop [ios] APNS, Remote Push 사용자가 수신을 동의했는지 확인하기 hooni 2018.10.19 1363
» Develop [js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식) hooni 2017.12.14 1350
Board Pagination Prev 1 ... 62 63 64 65 66 ... 74 Next
/ 74