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
번호 분류 제목 글쓴이 날짜 조회 수
649 Develop [c] KNN(K-nearest neighbor) 패턴인식 과제.. file hooni 2013.04.23 7394
648 Develop [c] Mac OS 에 gmp(gmp.h) 라이브러리 설치 hooni 2016.10.03 1214
647 Develop [c] OpenGL 관측점 이동 hooni 2003.04.23 7611
646 Develop [c] OpenGL 마우스 이벤트 hooni 2003.04.23 8731
645 Develop [c] OpenGL 색 입방체의 회전(입체) hooni 2003.04.23 7870
644 Develop [c] OpenGL 시어핀스키 가스킷(p.73 - 첫시간) hooni 2003.04.23 8758
643 Develop [c] OpenGL 임시로 여기 올림.. hooni 2003.04.23 10324
642 Develop [c] OpenGL 직사각형(2D) 크기 확대/축소 hooni 2003.04.23 9070
641 Develop [c] openssl 샘플코드.. 어려움 ㅠㅠ file hooni 2013.04.23 7027
640 Develop [c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ file hooni 2013.04.23 6902
639 Develop [c] pcap을 이용한 패킷 분석 ㅎㅎ hooni 2003.04.23 10210
638 Develop [c] RSA 암호화 구현(gmp 라이브러리 활용) file hooni 2016.10.03 888
Board Pagination Prev 1 ... 12 13 14 15 16 17 18 19 20 21 ... 71 Next
/ 71