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
번호 분류 제목 글쓴이 날짜 조회 수
97 Develop [c] 시간 관련 함수 설명과 예제.. file hooni 2003.04.23 11525
96 Develop [c] 문자열 처리 관련 함수들 설명 hooni 2003.04.23 7997
95 Develop [linux] 프로세스 관련 시스템콜 hooni 2003.04.23 7827
94 Develop [c] 시간 계산 하는 프로그램 소스코드 file hooni 2003.04.23 6746
93 Develop [php] 마시마로 캐릭터 방명록 file hooni 2003.04.23 8239
92 Develop [c] OpenGL 색 입방체의 회전(입체) hooni 2003.04.23 7870
91 Develop [c] 신기한 atoi함수(www.game79.net) hooni 2003.04.23 7274
90 Develop [c][java] 소켓 프로그래밍(채팅 서버 C, 클라이언트 Java) file hooni 2003.04.23 7011
89 Develop [js] 점점 커지는 새창.. hooni 2003.04.23 6998
88 Develop [c] OpenGL 마우스 이벤트 hooni 2003.04.23 8731
87 Develop [js] 사라지는 브라우저 hooni 2003.04.23 6857
86 Develop [js] 이벤트 핸들러(Event Handlers) hooni 2003.04.23 6729
Board Pagination Prev 1 ... 58 59 60 61 62 63 64 65 66 67 ... 71 Next
/ 71