Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1111 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
717 | Develop | [php] XE 관리자 IP대역 설정 오류 해결법 | hooni | 2014.02.10 | 10781 |
716 | System/OS | [mysql] 시간 관련 SQL구문.. | hooni | 2013.04.23 | 10777 |
715 | Develop | [c++] 가짜 인증서(하나은행) 프로그램 | hooni | 2013.04.23 | 10764 |
714 | System/OS | [linux] 프로세스의 stat 상태에 대한 설명 | hooni | 2013.04.23 | 10762 |
713 | Develop | [c++] p.118 확인학습 5번 | hooni | 2003.04.23 | 10736 |
712 | Develop | [c++]현승이가 보내준 암호화 모듈 AES라인델.. | hooni | 2003.04.23 | 10715 |
711 | Develop | [js] jQuery plugin 요약 | hooni | 2013.12.20 | 10703 |
710 | Develop | [php] GregorianToJD(), JDToGregorian() 함수 내용 | hooni | 2013.12.25 | 10597 |
709 | System/OS | [perl] 영규가 만든 스크립트.. 하하.. | hooni | 2013.04.23 | 10597 |
708 | Develop | [php] 날짜 정보 출력 (년,월,일,시,분,초) | hooni | 2013.04.23 | 10532 |
707 | System/OS | [linux] SSH에 대한 기본 설명과 설치/설정 | hooni | 2013.04.23 | 10503 |
706 | System/OS | [doc] 레드햇 리눅스 메뉴얼 (html버전) | hooni | 2013.04.23 | 10452 |