Contents

?

단축키

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. 선과 악에 대한 영어논술문항(지킬앤하이드 독서 후 이어지는 심화 수행평가)

  2. [js] Closure를 이용해 캡슐화..

  3. [js] jQuery 코드 작성시 편리한 HTML 템플릿

  4. [js] jQuery 셀랙터(selector) 요약

  5. [js] jQuery 배열 루프(each)

  6. [js] 객체 머지..

  7. [js] jQuery 충돌 회피

  8. [js] jQjuery $ 활용

  9. [js] 순환참조에 의한 메모리 누수 관련

  10. [js] jQuery 치트 시트

  11. [js] 이벤트 전파 3단계

  12. CentOS 6.5 USB 설치

Board Pagination Prev 1 ... 64 65 66 67 68 69 70 71 72 73 ... 98 Next
/ 98