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
번호 분류 제목 글쓴이 날짜 조회 수
417 Develop [pdf] 포인터 문법 정리 (C pointer) file hooni 2013.04.23 7146
416 Develop [js] 여러가지 트리(tree) 모음.. ㅋㅋ file hooni 2013.04.23 7138
415 Develop [c] 문자열 뒤집기 초간단 샘플 코드 ㅎㅎ hooni 2013.04.23 7136
414 Develop [c++] 인라인 함수에 대한 설명 hooni 2013.04.23 7132
413 Develop [php] 초간단 웹 카운터.. file hooni 2003.04.23 7129
412 Develop [c] 베이지언(Bayesian) 패턴인식 과제 ㅋㅋ file hooni 2013.04.23 7119
411 Develop [c] 테트리스3D (Tetris 3D) file hooni 2013.04.23 7117
410 Develop [c] 단기과정[01/14] 피보나치, 파스칼.. 파일입출력 file hooni 2003.04.23 7117
409 Develop [js] 2차 잉여.. (Quadratic reciprocity) 계산.. file hooni 2013.04.23 7099
408 Develop [c] 구조체/파일 입출력 프로그램 file hooni 2003.04.23 7088
407 Develop [c++] mfc 기반 멀티수납(wall)시스템 소스와 실행파일 file hooni 2013.04.23 7084
406 Develop [c] 내가 만든 암호화 프로그램.. 좋아^^ file hooni 2013.04.23 7084
Board Pagination Prev 1 ... 59 60 61 62 63 64 65 66 67 68 ... 98 Next
/ 98