Contents

?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

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
No. Category Subject Author Date Views
1137 Develop [ios] VIN Scanner (VIN barcode) 스캐너 file hooni 2017.09.16 648
1136 Develop [ios] NSNotificationCenter 초간단 사용 예~ ㅋㄷ hooni 2015.06.26 654
1135 Develop [ios] SBCampanion App 초안 file hooni 2015.09.16 656
1134 Database [mysql] MySql DB/테이블 사이즈 확인을 위한 쿼리 hooni 2019.11.22 660
1133 Develop [ios] WWDC 2015 샘플 소스 코드 통합파일 hooni 2015.07.20 661
1132 Database [mysql] MySQL 데이터베이스 추가 및 사용자 추가 hooni 2019.11.22 666
1131 Develop [ios] Touch ID 적용 샘플 코드 (예제) file hooni 2015.02.23 670
1130 Develop [ios] 여러 버전의 Xcode 사용하기 hooni 2022.05.28 671
1129 Develop Aspect Oriented Programming in Objective-C hooni 2015.05.18 674
1128 Develop [swift] 실행시간 측정하기 hooni 2021.09.14 676
1127 Develop 정리할 자료. file hooni 2015.07.02 677
1126 Develop [js] Text 값을 클립보드에 복사하기 hooni 2020.10.10 679
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98