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
번호 분류 제목 글쓴이 날짜 조회 수
1101 System/OS [linux] 프로그램 설치방법 (내공쌓기) hooni 2003.04.23 13433
1100 System/OS [linux] 계정관리하기(내공쌓기) hooni 2003.04.23 13156
1099 System/OS [linux] 기본적인 설정하기(내공쌓기) hooni 2003.04.23 13993
1098 System/OS [linux] 새 하드디스크 추가하기..(내공쌓기) hooni 2003.04.23 13807
1097 System/OS [linux] 아파치설치/설정 hooni 2003.04.23 14492
1096 System/OS [linux] 아파치설치/설정(CGI부분) hooni 2003.04.23 14568
1095 System/OS [linux] 아파치설치/설정 - SSI(Server Side Include) hooni 2003.04.23 13206
1094 System/OS [linux] 아파치 설치/설정(proxy) hooni 2003.04.23 12965
1093 System/OS [linux] 아파치설치/설정(모니터링) hooni 2003.04.23 14153
1092 System/OS [linux] 아파치설치/설정 - 사용인증 hooni 2003.04.23 15084
1091 System/OS [linux] 아파치설치/설정 - 알리어싱(aliasing) hooni 2003.04.23 51367
1090 System/OS [linux] 랜카드가 2개 일 때 네트워크 설정 hooni 2003.04.23 30007
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 11 ... 98 Next
/ 98