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
번호 분류 제목 글쓴이 날짜 조회 수
817 Develop [c++] p.47 연습문제 3번 hooni 2003.04.23 10105
816 Develop [c++] p.58 연습문제 2번 hooni 2003.04.23 16296
815 Develop [c++] p.118 확인학습 5번 hooni 2003.04.23 10734
814 Develop [c] 프로그래밍 ppt, 스킬업 (비트 수업자료) file hooni 2003.04.23 8177
813 Develop [css] 스크롤바 안생기게 hooni 2003.04.23 9886
812 Develop [c] 민수형 libipq 샘플 소스 ㅋㅋ hooni 2003.04.23 14112
811 Develop [php] 니우쪽지다.. 받아라~ ^^ file hooni 2003.04.23 9834
810 Develop [c++]현승이가 보내준 동영상 암호화 자료.. 볼것.. file hooni 2003.04.23 9728
809 Develop [c++]현승이가 보내준 암호화 모듈 AES라인델.. file hooni 2003.04.23 10714
808 Develop [php] 배열 관련 함수 설명 ㅎㅎ hooni 2003.04.23 11742
807 Develop [css] 화면 스크롤 제어 ㅋㅋ hooni 2003.04.23 8681
806 Develop [js] 자바스크립트 이벤트 핸들.. hooni 2003.04.23 7908
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 71 Next
/ 71