조회 수 3459 추천 수 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
번호 분류 제목 글쓴이 날짜 조회 수
169 Develop [python] 파이썬 공부하는 사이트~ hooni 2013.11.12 11832
168 Develop [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기) hooni 2019.12.06 3680
167 System/OS [router] 라우팅 프로토콜 BGP (간단한 세팅) hooni 2013.04.23 11645
166 System/OS [router] 설정과 기본 명령어들 모음 hooni 2013.04.23 16451
165 System/OS [router] 시스코 라우터 명령어 모드.. hooni 2013.04.23 13674
164 Algorithm [security] RSA 암호화 설명과 예.. hooni 2013.04.23 18061
163 Algorithm [security] 블럭 암호에 대해서.. hooni 2013.04.23 18470
162 Develop [sh] html 안에 있는 img 다운 받는 쉘 스크립트 file hooni 2020.05.26 2556
161 Develop [sh] 쉘스크립트 if 비교 연산 hooni 2020.05.26 64333
160 Develop [spring] 스프링 IoC/DI hooni 2013.04.23 12383
159 System/OS [sql] alter table 쿼리 예제 hooni 2003.04.23 13314
158 System/OS [sql] insert into select 사용하기 hooni 2013.04.23 31854
157 Database [sql] 간단한 SQL 문법 정리 hooni 2003.04.23 14045
156 Database [sql] 간단한 통계 서브쿼리 예제.. hooni 2013.04.23 16423
155 System/OS [sql] 내 방명록 답글 찾는 쿼리문.. (JOIN 구문) hooni 2003.04.23 13774
154 System/OS [sql] 조회구문(select)에서 중복 데이터를 한 번만 출력 (distinct) 1 hooni 2013.04.23 35644
Board Pagination Prev 1 ... 62 63 64 65 66 ... 74 Next
/ 74