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 [js] 폼(form) 전송시 중복 클릭 방지 간단한 구문 hooni 2013.04.23 10113
254 Develop [js] 사진첩에 쓸 내용 - 마우스 오버로 바꾸기 hooni 2013.04.23 7436
253 Develop [java] Sieve of Eratosthenes (에라토스테네스의 체) hooni 2013.04.23 10464
252 Develop [c] 유닉스 프로그램에서 인수처리 해주는 getopt() 함수 file hooni 2013.04.23 9313
251 Develop [c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ file hooni 2013.04.23 8057
250 Develop [php] 무조건 다운로드 받도록 header 세팅 file hooni 2013.04.23 8385
249 Develop [php] 자바스크립트 개판 만들기.. file hooni 2013.04.23 8528
248 Develop [js] 자바스크립트로 만든 게임 file hooni 2013.04.23 9342
247 Develop [js] 윤동이가 만든 영어 학습(?) 프로그램 file hooni 2013.04.23 7974
246 Develop [js] 밀리터리 프로그램(전역일 계산) 7 file hooni 2013.04.23 11132
245 Develop [js] 빈도우즈(bindows96) file hooni 2013.04.23 8335
244 Develop [js] 후리자(영규) 스타일들.. file hooni 2013.04.23 8341
Board Pagination Prev 1 ... 45 46 47 48 49 50 51 52 53 54 ... 71 Next
/ 71