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
번호 분류 제목 글쓴이 날짜 조회 수
1149 Etc 영어의 12 시제 (The twelve tenses of English) hooni 2013.07.12 15699
1148 Etc 영어공부에 도움될만한 사이트 모음 hooni 2013.05.14 22628
1147 Etc 영어. 외우면 도움되는 필수영어회화 표현 file hooni 2013.09.09 20923
1146 Etc 영어. 불규칙 동사 정리 file hooni 2017.10.04 3480
1145 Etc 영어. 반드시 외워야 할 영어 숙어 2 file hooni 2016.07.07 6313
1144 Etc 영어. 반드시 외워야 할 문장 패턴 100개 file hooni 2023.06.08 902
1143 Etc 영어. 반드시 외워야 할 단어 file hooni 2016.07.07 1949
1142 Etc 영어 아주 쉬운 영작문 강의 01~60 secret hooni 2013.06.25 0
1141 Etc 영어 관련 토렌트 secret hooni 2013.06.25 0
1140 Etc 여러 대학 및 권위있는 기관 강좌 모음 ㅋㅋ hooni 2013.06.17 15115
1139 Etc 여기저기서 모은 VoIP(인터넷전화) 자료들~ file hooni 2013.04.23 15966
1138 Etc 엑셀 함수 총 정리 ㅎㅎ file hooni 2013.06.05 24458
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98