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
번호 분류 제목 글쓴이 날짜 조회 수
81 System/OS [linux] 아파치설치/설정(모니터링) hooni 2003.04.23 14159
80 System/OS [linux] 아파치 설치/설정(proxy) hooni 2003.04.23 12967
79 System/OS [linux] 아파치설치/설정 - SSI(Server Side Include) hooni 2003.04.23 13211
78 System/OS [linux] 아파치설치/설정(CGI부분) hooni 2003.04.23 14572
77 System/OS [linux] 아파치설치/설정 hooni 2003.04.23 14495
76 System/OS [linux] 새 하드디스크 추가하기..(내공쌓기) hooni 2003.04.23 13810
75 System/OS [linux] 기본적인 설정하기(내공쌓기) hooni 2003.04.23 13999
74 System/OS [linux] 계정관리하기(내공쌓기) hooni 2003.04.23 13187
73 System/OS [linux] 프로그램 설치방법 (내공쌓기) hooni 2003.04.23 13435
72 System/OS [linux] 간단한 vi편집기 사용 명령 hooni 2003.04.23 13460
71 System/OS [linux] 기본 명령어 (내공쌓기) hooni 2003.04.23 14336
70 System/OS [linux] 리눅스 활용 팁^^ hooni 2003.04.23 14634
Board Pagination Prev 1 ... 87 88 89 90 91 92 93 94 95 96 ... 98 Next
/ 98