Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 3536 댓글 0
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 parseInt
in that case, which may be as good as anything.
[출처] https://stackoverflow.com/questions/4460595/jquery-filter-numbers-of-a-string
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
721 | Develop | [ios] iOS In App Purchase 코드 부분 샘플 2 | hooni | 2013.11.20 | 12149 |
720 | Database | [mysql] 루트 암호 초기화 | hooni | 2013.04.23 | 12102 |
719 | Develop | [c] 소수 구하기 #2 (입력한 숫자가 소수인지 판별하기..) | hooni | 2013.04.23 | 12070 |
718 | Develop | [switch] 시스코 카탈리스트(Cisco Catalyst) 2950 미러링 설정 | hooni | 2013.04.23 | 12069 |
717 | Etc | [NFC] 단말기와 서버 통신 내용 | hooni | 2013.11.12 | 11957 |
716 | Develop | [c++] p.118 확인학습 5번 | hooni | 2003.04.23 | 11952 |
715 | Develop | [js] IE에서 인쇄 설정 팁 | hooni | 2013.04.23 | 11948 |
714 | System/OS |
[doc] TCP/IP 강의 자료 (html)
![]() |
hooni | 2013.04.23 | 11945 |
713 | System/OS | [linux] 프로세스의 stat 상태에 대한 설명 | hooni | 2013.04.23 | 11889 |
712 | Develop | [c] 간단한 링크드 리스트(linked list) 자료형 예제.. | hooni | 2003.04.23 | 11888 |
711 | Develop | [python] 파이썬 공부하는 사이트~ | hooni | 2013.11.12 | 11835 |
710 | Develop |
[c++] 가짜 인증서(하나은행) 프로그램
![]() |
hooni | 2013.04.23 | 11814 |