숫자이외 제거 javascript


var str = "2019-12-11";


str = str.replace(/[^0-9]/g,'');


console.log(str);


angularjs formatDate 필터


angular.module('dgs')

    // var testDate = $filter('formatDate')("2016-09-22","/");
  .filter('formatDate', function () {
    return function (input,seprator) {
        input  = input.replace(/[^0-9]/g,'');        // 20160926 -> 2016.09.26        // 2012-12-21 01:11:22 -> 2012.12.21        if(!seprator){
            seprator = ".";        }
        return ''+input.slice(0, 4) + seprator + input.slice(4,6)+ seprator + input.slice(6,8);    }
  })

})
;




댓글