Contents

?

단축키

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
번호 분류 제목 글쓴이 날짜 조회 수
255 Develop 도메인 관련 솔루션 분석할 거.. ㅋㄷ file hooni 2013.04.23 7975
254 Develop [js] 윤동이가 만든 영어 학습(?) 프로그램 file hooni 2013.04.23 7974
253 Develop [php] 빔 프로젝터 예약 프로그램.. ㅋㅋ file hooni 2013.04.23 7974
252 Develop [c] 프로세스간의 통신(파이프) hooni 2003.04.23 7973
251 Develop [php] 논문 관리 프로그램.. ㅋㅋ file hooni 2013.04.23 7973
250 Develop [js] 숫자만 입력하게 하는 자바스크립트 hooni 2013.04.23 7969
249 Develop [c++] 템플릿(Template) 예제 소스.. file hooni 2013.04.23 7969
248 Develop 라이브러리에 대한 설명 (static & dynamic library) hooni 2013.04.23 7966
247 Develop [web] 웹 연동 프로그램 모음.. file hooni 2013.04.23 7961
246 Develop [c++] template 사용예 hooni 2003.04.23 7959
245 Develop [c++] mfc로 만든 인테리어 수납 시스템(2D기반 설계) file hooni 2013.04.23 7959
244 Develop [js] 양원님이 공유해 주신 유료(5$란다ㅋ) 자료 ㅋㅋ secret hooni 2013.04.23 7948
Board Pagination Prev 1 ... 45 46 47 48 49 50 51 52 53 54 ... 71 Next
/ 71