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
번호 분류 제목 글쓴이 날짜 조회 수
1029 Develop [jsp] Get방식, Post방식 전송 예제.. file hooni 2003.04.23 13791
1028 Develop [c++] 기초강좌 #01(입출력,영역지정) hooni 2003.04.23 11458
1027 Develop [c++] 기초강좌 #02(레퍼런스,메모리할당) hooni 2003.04.23 11473
1026 Develop [c++] 기초강좌 #03(함수의 매개변수 전달) hooni 2003.04.23 12128
1025 Develop [c++] 기초강좌 #04(클래스) hooni 2003.04.23 11860
1024 Develop [c] C로 구현한 CGI - 방명록 file hooni 2003.04.23 33500
1023 Develop [c] C로 구현한 CGI - 계산기 (링크리스트, 스택, 이진트리) file hooni 2003.04.23 28142
1022 Develop [c] C로 구현한 CGI - 달력과 날짜계산기 file hooni 2003.04.23 32434
1021 Develop [jsp] 유효성체크(Client, Server 에서) file hooni 2003.04.23 7456
1020 Develop [js] 키보드 아스키 코드 확인하는 간단한 소스 hooni 2003.04.23 7787
1019 Develop [js] 핫키(단축키) 구현방법 hooni 2003.04.23 7649
1018 Develop [js] 이미지 미리 로딩하기 hooni 2003.04.23 7033
Board Pagination Prev 1 ... 8 9 10 11 12 13 14 15 16 17 ... 98 Next
/ 98