조회 수 3484 추천 수 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
번호 분류 제목 글쓴이 날짜 조회 수
91 Develop [js] 모바일 스크롤 방지(해제) hooni 2015.04.14 3046
90 Develop [Javascript][Ajax] 자바스크립트 강의 산출물 file hooni 2019.10.05 3030
89 Develop [swift] 실행시간 측정하기 hooni 2021.09.14 3020
88 Develop [android] 간단한 SQLIite 예제 hooni 2017.06.14 3008
87 Develop [ios] GPS 이용 상태 확인 hooni 2015.04.27 2935
86 Develop [ios] 카메라 사용 권한 확인해서 분기하는 방법 hooni 2015.02.26 2884
85 Develop [c#] 툴바 현재 욜심히 만들고 있는거.. 백업용.. ㅋㅋ secret hooni 2013.04.23 2852
84 Develop [ios] 상위 ViewController 가져오기 hooni 2015.10.12 2841
83 Develop 캘리포니아 운전면허 족보 file hooni 2017.06.12 2817
82 Develop [kotlin] 코틀린 안드로이드 앱 버전/빌드 정보 hooni 2020.12.15 2809
81 Develop [ios] @property의 속성 (strong, weak, copy) 사용 경우 hooni 2014.08.08 2807
80 Develop [ios] 코코아 프로그래밍의 네이밍 룰(명명 규칙) hooni 2017.05.11 2788
79 Develop [android] Android N requires the IDE to be running with Java 1.8 or later 오류 hooni 2016.08.30 2781
78 Develop [android] 레이아웃 사이즈 변경 (동적; programmatically) hooni 2016.11.07 2781
77 Develop [php] 한글 문자열 자르기 (utf-8) hooni 2015.11.10 2776
76 Develop [c] RSA 암호화 구현(gmp 라이브러리 활용) file hooni 2016.10.03 2744
Board Pagination Prev 1 ... 46 47 48 49 50 53 Next
/ 53