조회 수 1354 추천 수 0 댓글 0
?

단축키

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
번호 분류 제목 글쓴이 날짜 조회 수
57 Develop [unix] Java 애플릿용 HTML 자동 생성 hooni 2014.02.19 8268
56 Develop [unix] 날짜 관련 쉘 명령어 (특정일 또는 +-시간, 날짜 계산된 값) hooni 2013.04.23 14888
55 Develop [unix] 로그파일 정리 쉘스크립트 hooni 2014.02.19 10879
54 Develop [unix] 쉘 스크립트 예제 모음 hooni 2003.04.23 15010
53 Develop [unix] 유닉스 명령에 메타문자 사용 hooni 2014.02.19 11298
52 Develop [vbs] CD롬 뱉는 스크립트.. hooni 2003.04.23 11739
51 Develop [vb] 64bit RSA 프로그램 소스 ㅋㅋ file hooni 2013.04.23 8233
50 Develop [vb] 문자열에서 태그 제거함수 (Visual Basic) file hooni 2013.04.23 22678
49 Develop [vb] 비주얼 베이직 131페이지 hooni 2003.04.23 58161
48 Develop [vb] 비주얼 베이직 141페이지 hooni 2003.04.23 59021
47 Develop [vb] 비주얼 베이직 173페이지 hooni 2003.04.23 54915
46 Develop [vb] 비주얼 베이직 205페이지 hooni 2003.04.23 56137
45 Develop [vb] 비주얼 베이직 순위 정렬 루틴 hooni 2003.04.23 58436
44 Develop [vb] 비주얼 베이직 자격증용 ㅎㅎ hooni 2003.04.23 61582
43 Develop [vb] 비쥬얼 베이직 기출 문제 연습 hooni 2003.04.23 55241
42 Develop [vb] 비쥬얼 베이직 기출 문제 연습2 hooni 2003.04.23 54447
Board Pagination Prev 1 ... 48 49 50 51 52 53 Next
/ 53