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
번호 분류 제목 글쓴이 날짜 조회 수
109 Develop [c] 간단한 순위 루틴.. (정보처리기사) hooni 2003.04.23 6905
108 Develop [c] fgets() 함수 사용하기.. hooni 2003.04.23 7854
107 Develop [c] 싱글, 더블 링크리스트(linked list)로 만든 예제.. file hooni 2003.04.23 6766
106 Develop [c] 컴파일러 선행처리기 따라하기.. file hooni 2003.04.23 6702
105 Develop [c] 구조체/파일 입출력 프로그램 file hooni 2003.04.23 7085
104 Develop [c++] 더블 링크리스트(linked list) 학습용 초간단 단어장 file hooni 2003.04.23 9366
103 Develop [c] OpenGL 직사각형(2D) 크기 확대/축소 hooni 2003.04.23 9097
102 Develop [jsp] 정적/동적(차트생성) 이미지 전달 file hooni 2003.04.23 7340
101 Develop [c] 프로세스간의 통신(파이프) hooni 2003.04.23 6915
100 Develop [c] 구조체의 설명과 예제.. hooni 2003.04.23 8400
99 Develop [c] 포인터와 함수포인터에 대해.. hooni 2003.04.23 8044
98 Develop [c] 스토리지 클래스(변수) hooni 2003.04.23 8221
Board Pagination Prev 1 ... 57 58 59 60 61 62 63 64 65 66 ... 71 Next
/ 71