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
번호 분류 제목 글쓴이 날짜 조회 수
721 Develop [ios] 아이폰 개발 총정리.. file hooni 2013.04.23 25120
720 Develop [ios] 구분자로 문자열 자르기 (split) hooni 2013.04.23 26990
719 Develop [iphone] view에 대한 조사 ㅡ,.ㅡ; file hooni 2013.04.23 54987
718 Develop [ios] NSMutableString 문자열 패턴 교환 hooni 2013.04.23 30110
717 Develop 논문 실험용 고려대 툴바 ㅎㅎ secret hooni 2013.04.23 8686
716 Develop [ios] 개발 기초 가이드 링크.. hooni 2013.04.23 32325
715 System/OS 맥북에서 MAC/윈도우 멀티부팅시 시간 설정 file hooni 2013.04.23 31247
714 Develop 웹페이지 성능 테스트 툴 설명 hooni 2013.04.23 28447
713 Develop [Xcode] 디버깅 옵션 file hooni 2013.04.23 58042
712 Algorithm 러시아 페인트공 알고리즘에 대해.. hooni 2013.04.23 24521
711 Develop [ios] Objective-C 문자열 잘라서 배열(NSArray)에 넣기 hooni 2013.04.23 30454
710 Develop [ios] Objective-C 특정 문자 찾아 제거하기 hooni 2013.04.23 29227
Board Pagination Prev 1 ... 34 35 36 37 38 39 40 41 42 43 ... 99 Next
/ 99