Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1092 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
23 | Database | [mysql] 접속과 테이블 생성 간단한 설명.. | hooni | 2003.04.23 | 18650 |
22 | Database | [mysql] 쿼리 로그 저장 매뉴얼 | hooni | 2013.04.23 | 15210 |
21 | Database | [sql] 간단한 통계 서브쿼리 예제.. | hooni | 2013.04.23 | 15082 |
20 | Database | [mysql] 쓰레드가 계속 쌓이기 시작하고 사라지지 않을때.. | hooni | 2003.04.23 | 12783 |
19 | Database | [mysql] error while loading shared libraries: libmysqlclient.so.10: | hooni | 2003.04.23 | 12660 |
18 | Database | [sql] 간단한 SQL 문법 정리 | hooni | 2003.04.23 | 12547 |
17 | Database | [mysql] DB->Text, Text->DB 변환 | hooni | 2003.04.23 | 12126 |
16 | Database | [oracle] SQL문 실행 방법 3가지 | hooni | 2013.12.19 | 12115 |
15 | Database | [mysql] 루트 암호 초기화 | hooni | 2013.04.23 | 11038 |
14 | Database | [sql] 쿼리로 문자열 검색해서 일괄 치환하기 | hooni | 2014.02.13 | 9961 |
13 | Database | [mysql] 쿼리 실행시 ERROR 1366 (HY000) : incorrect string value : for column 3 | hooni | 2017.03.30 | 8716 |
12 | Database | [sql] 한눈에 보이는 Join | hooni | 2014.02.19 | 8453 |