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
번호 분류 제목 글쓴이 날짜 조회 수
1141 Develop [ios] URL 랜딩 속도(OpenURL 10초 정지되는) 이슈 hooni 2015.02.09 1768
1140 Develop [ios] iOS 8 개발자가 우선 알아야 할 3가지 file hooni 2014.10.02 1796
1139 Develop [ios] Touch ID 적용 샘플 코드 (예제) file hooni 2015.02.23 1842
1138 Develop [ios] WWDC 2015 샘플 소스 코드 통합파일 hooni 2015.07.20 1843
1137 Develop [ios] 문자열로 함수 실행하기 (eval 함수처럼) hooni 2015.02.10 1846
1136 Develop [ios] NSNotificationCenter 초간단 사용 예~ ㅋㄷ hooni 2015.06.26 1863
1135 Develop [ios] 새로 만들고 있는 DateMemo file hooni 2016.07.12 1903
1134 Develop [ios] UIWebView에서 로컬에 있는 html 파일 불러오기 hooni 2015.02.10 2009
1133 Develop [ios] SBCampanion App 초안 file hooni 2015.09.16 2018
1132 System/OS 개인적으로 쓰고 있는 bash_profile hooni 2015.01.16 2020
1131 Develop [c] 이진 탐색 두 가지 코드 (재귀/반복) file hooni 2015.06.26 2033
1130 Develop [ios] NSData to NSString (NSString to NSData) hooni 2015.07.21 2033
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 99 Next
/ 99