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
번호 분류 제목 글쓴이 날짜 조회 수
717 Develop [c] 신기한 atoi함수(www.game79.net) hooni 2003.04.23 7274
716 Develop [js] 초간단 현재 사이트 쿠키 확인하는 명령~ hooni 2003.04.23 7275
715 Develop [pdf] C++ 국제 표준 문서 file hooni 2013.04.23 7281
714 Develop [c++] mfc로 만든 사용자 계정 리스트 출력(EnumUser) 프로그램 예제 file hooni 2013.04.23 7290
713 Develop [c]디렉토리 탐색 file hooni 2003.04.23 7303
712 Develop [jsp] 정적/동적(차트생성) 이미지 전달 file hooni 2003.04.23 7307
711 Develop 객체지향 프로그래밍에 대한 개념.. (객체) file hooni 2013.04.23 7310
710 Develop [php] 이미지 회전시키기(gd) hooni 2013.04.23 7318
709 Develop [c] 플러드 필링 (flood filling) 알고리즘.. file hooni 2013.04.23 7319
708 Develop [c/c++] Makefile 사용하기.. ㅋㅋ hooni 2003.04.23 7321
707 Develop [c] 스택/힙 오버플로우 테스트(overflow) file hooni 2003.04.23 7324
706 Develop [ios] How To Use UIScrollView to Scroll and Zoom Content (Using Swift) file hooni 2016.03.23 7348
Board Pagination Prev 1 ... 34 35 36 37 38 39 40 41 42 43 ... 98 Next
/ 98