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
번호 분류 제목 글쓴이 날짜 조회 수
253 Develop [java] Sieve of Eratosthenes (에라토스테네스의 체) hooni 2013.04.23 9348
252 Develop [c] 유닉스 프로그램에서 인수처리 해주는 getopt() 함수 file hooni 2013.04.23 8090
251 Develop [c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ file hooni 2013.04.23 6914
250 Develop [php] 무조건 다운로드 받도록 header 세팅 file hooni 2013.04.23 7421
249 Develop [php] 자바스크립트 개판 만들기.. file hooni 2013.04.23 7684
248 Develop [js] 자바스크립트로 만든 게임 file hooni 2013.04.23 8412
247 Develop [js] 윤동이가 만든 영어 학습(?) 프로그램 file hooni 2013.04.23 6478
246 Develop [js] 밀리터리 프로그램(전역일 계산) 7 file hooni 2013.04.23 8931
245 Develop [js] 빈도우즈(bindows96) file hooni 2013.04.23 7395
244 Develop [js] 후리자(영규) 스타일들.. file hooni 2013.04.23 7179
243 Develop [js] 여러가지 트리(tree) 모음.. ㅋㅋ file hooni 2013.04.23 7135
242 Develop [js] IE에서 인쇄 설정 팁 hooni 2013.04.23 10921
Board Pagination Prev 1 ... 45 46 47 48 49 50 51 52 53 54 ... 71 Next
/ 71