get only number from value - Javascript Data Type

Javascript examples for Data Type:Number

Description

get only number from value

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
var tel = "(123)123-2432";
var getLength = function(tel){
  var telStr = tel.split('');
  var excpetionList = ['(',')','-'];
  return telStr.filter(function(item,index,arr){
     if(excpetionList.indexOf(item) < 0){
       return item;/*from w ww  .  j a va2s.  c  o  m*/
     }
  }).join('').length;
};
console.log(getLength(tel));

      </script>  
   </body>
</html>

Related Tutorials