Develop
2017.12.14 16:10
[js] 문자열에서 숫자만 걸러내기 (jQuery 안쓰고 정규표현식)
조회 수 1125 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1137 | Develop |
[ios] VIN Scanner (VIN barcode) 스캐너
![]() |
hooni | 2017.09.16 | 664 |
1136 | Develop | [ios] NSNotificationCenter 초간단 사용 예~ ㅋㄷ | hooni | 2015.06.26 | 666 |
1135 | Develop |
[ios] SBCampanion App 초안
![]() |
hooni | 2015.09.16 | 670 |
1134 | Database | [mysql] MySql DB/테이블 사이즈 확인을 위한 쿼리 | hooni | 2019.11.22 | 676 |
1133 | Develop |
[ios] Touch ID 적용 샘플 코드 (예제)
![]() |
hooni | 2015.02.23 | 678 |
1132 | Database | [mysql] MySQL 데이터베이스 추가 및 사용자 추가 | hooni | 2019.11.22 | 682 |
1131 | Develop | [ios] 여러 버전의 Xcode 사용하기 | hooni | 2022.05.28 | 684 |
1130 | Develop | [ios] WWDC 2015 샘플 소스 코드 통합파일 | hooni | 2015.07.20 | 688 |
1129 | Develop | [js] Text 값을 클립보드에 복사하기 | hooni | 2020.10.10 | 690 |
1128 | Develop |
정리할 자료.
![]() |
hooni | 2015.07.02 | 691 |
1127 | Develop | Aspect Oriented Programming in Objective-C | hooni | 2015.05.18 | 692 |
1126 | Develop |
[matlab] 정보은닉 스테가노그래피(Steganography) 수업
![]() |
hooni | 2016.10.03 | 696 |