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
번호 분류 제목 글쓴이 날짜 조회 수
421 Develop [c] 연산자 우선순위.. ㅋㅋ hooni 2013.04.23 8305
420 Develop [c] 지폰(gphone) 소스.. 수정(암호화) file hooni 2013.04.23 8291
419 Develop [c] 신기한 atoi함수(www.game79.net) hooni 2003.04.23 8283
418 Develop [asp] 기본 문법과 제어문 hooni 2013.04.23 8282
417 Develop [c] 로또(Lotto) 번호 생성기 file hooni 2013.04.23 8279
416 Develop [linux] crond 사용법.. ㅋㅋ hooni 2013.04.23 8270
415 Develop [js] php의 number_format() 함수와 같은.. ㅋㅋ hooni 2013.04.23 8266
414 Develop [js] 한글문서로 된 259가지 자바스크립트 예제파일 file hooni 2013.04.23 8263
413 Develop [pdf] 포인터 문법 정리 (C pointer) file hooni 2013.04.23 8262
412 Develop [linux] 임베디드 리눅스 (embedded linux) file hooni 2013.04.23 8262
411 Develop [c] 게임 AI FSM 테스트 샘플 소스.. 꽤 괜찮은 소스.. file hooni 2013.04.23 8248
410 Develop [c] 문자열 라이브러리 최신버전 file hooni 2003.04.23 8247
Board Pagination Prev 1 ... 59 60 61 62 63 64 65 66 67 68 ... 99 Next
/ 99