조회 수 1100 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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

?

  1. [ios] VIN Scanner (VIN barcode) 스캐너

  2. [android] 안드로이드 앱 문서 샘플

  3. [coding] 공부해야 하는거 ㅋㅋ

  4. [coding] Find all anagrams in a string

  5. [android] SQLiteOpenHelper를 이용한 DBManager

  6. [android] 간단한 SQLIite 예제

  7. 캘리포니아 운전면허 족보

  8. 사이버보안실무 발표자료 (2017.06.08)

  9. 리팩토링 계획안

  10. [ios] 코코아 프로그래밍의 네이밍 룰(명명 규칙)

  11. [ios] Facebook SDK 로그인 설명

  12. [ios] NSString, RegularExpression Find/Replace

  13. [ios] 비디오,네트워크,소셜로그인 테스트

  14. [ios] Xcode에서 특정 파일만 ARC 따로 설정하는 방법

  15. 사이버보안실무 수업 메모

  16. Mac OS 에 Jenkins 설치하기 (Homebrew)

Board Pagination Prev 1 2 3 4 5 6 ... 53 Next
/ 53