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
번호 분류 제목 글쓴이 날짜 조회 수
831 Develop 알고리즘 성능 분석 기준 hooni 2014.06.24 3992
830 Develop 아이 훌레시 작업중 ㅋㅋ secret hooni 2013.08.09 0
829 Develop 서기의 PHP 동영상 강의(싱싱해) hooni 2013.05.15 31898
828 Develop 사이버보안실무 수업 메모 secret hooni 2017.03.23 0
827 Develop 사이버보안실무 발표자료 (2017.06.08) file hooni 2017.06.05 9941
826 Develop 베지어 곡선(Bézier curve) 알고리즘(spline 곡선) 3 file hooni 2013.04.23 35266
825 Develop 밸런싱 로봇.. 최종.. (관련 논문도 첨부) ㅋㅋ file hooni 2013.04.23 24158
824 Develop 모터에 대한 pid 제어.. ㅎㅎ file hooni 2013.04.23 19730
823 Develop 링크들 보고 지울 내용 secret hooni 2019.11.21 0
822 Develop 리팩토링 계획안 file hooni 2017.05.15 2357
821 Develop 레고 마인드스톰 NXT 수도쿠, 큐브 소스코드.. 20 file hooni 2013.04.23 83100
820 Develop 레고 NXT 마인드스톰 밸런싱 로봇 ㅎㅎ file hooni 2013.04.23 58764
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 71 Next
/ 71