Views 1100 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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
No. Category Subject Author Date Views
1077 Develop [Xcode] 디버깅 옵션 file hooni 2013.04.23 57196
1076 Develop [winmobile] 윈도우 모바일 간단한 테스트 코드 ㅋㅋ file hooni 2013.04.23 17081
1075 System/OS [windows] 패스워드를 잊어먹었을때.. hooni 2003.04.23 17294
1074 System/OS [windows] 최근 열어본 문서목록 안나오게 하는 방법 hooni 2013.04.23 25477
1073 System/OS [windows] 종료, 재시작, 로그아웃 아이콘 만들기 hooni 2013.04.23 18102
1072 System/OS [windows] 인터넷 익스플로러(IE) 도구모음 표시줄에 아이콘 추가 file hooni 2013.04.23 18219
1071 System/OS [windows] 윈도우즈 콘솔에서 정품인증 하는 방법 hooni 2017.05.24 5301
1070 System/OS [windows] 윈도우 사용자 계정 로그인 암호 분실, 암호 변경하는 방법 file hooni 2015.07.09 21355
1069 System/OS [windows] 원격 데스크탑(터미널 서비스) 포트 변경 hooni 2013.04.23 16304
1068 System/OS [windows] 여러가지 활용 팁 hooni 2003.04.23 19969
1067 System/OS [windows] 배치(bat)파일 제작 방법 hooni 2003.04.23 17002
1066 System/OS [windows] 도스 사용 팁 hooni 2003.04.23 17806
1065 System/OS [windows] 98/ME 속도 빠르게 튜닝(부팅,메모리,레지스터) hooni 2003.04.23 50439
1064 Etc [web] 제로보드 XE 템플릿에서 if문에 대해서 알아봅시다 hooni 2013.08.16 19803
1063 System/OS [web] 웹서비스 취약점 자료.. (논문첨부) file hooni 2003.04.23 17940
1062 Develop [web] 웹 연동 프로그램 모음.. file hooni 2013.04.23 6960
Board Pagination Prev 1 5 6 7 8 9 ... 74 Next
/ 74