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
번호 분류 제목 글쓴이 날짜 조회 수
111 Develop [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs) hooni 2019.11.22 3795
110 Develop [ios] Locale Identifiers file hooni 2018.11.29 3725
109 Develop [python][django] request.cookie 읽어오기 ㅋㅋㅋ (쓰기) hooni 2019.12.06 3713
108 Develop [ios] XCode에서 Provisioning Profile 여러개 중복될 때 hooni 2014.06.26 3702
107 Develop [ios] 설정에서 푸시 알림(APNS) on/off 상태 확인 hooni 2015.04.28 3592
106 Develop [android] SQLiteOpenHelper를 이용한 DBManager hooni 2017.06.14 3582
105 Develop [ios] 카테고리 확장 메소드를 찾지 못하는 경우 file hooni 2014.08.08 3555
» Develop [js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식) hooni 2017.12.14 3554
103 Develop [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #2 (client) hooni 2015.01.02 3546
102 Develop [ios] Objective-C 에서 자주 사용하는 수학 함수와 유용한 Define hooni 2014.08.08 3515
101 Develop [ios] GMT Date와 Local Date 변환하기 hooni 2015.04.07 3399
100 Develop [ios] 배경에 Gradient 적용하기 (CAGradientLayer) file hooni 2024.12.14 3361
Board Pagination Prev 1 ... 57 58 59 60 61 62 63 64 65 66 ... 71 Next
/ 71