Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
javascript function to detcte the regex for string along with number

I have this code for checking if it's a string please use some regex to extract only numbers, but in some cases i do have this:

Column1     Column2
($75.00)    $0.00 PayPal Email Declined

var intVal = function(i) {
  console.log(i);
  return typeof i === 'string' ?
    i.replace(/[\$,]/g, '') * 1 :
    typeof i === 'number' ?
    i : 0;
};

what regex needs to modify so i get the numbers values only

Update #1

Because i am doing datatables calculation in tfoot, i am using this code

"footerCallback": function ( row, data, start, end, display ) {
            var api = this.api();
            
            var intVal = function ( i ) {
                return typeof i === 'string' ? i.replace(/[^0-9]/g, '') * 1 : typeof i === 'number' ? i : 0;
            };
            
            ColumnThreeTotal = api
                .column(3, {page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );
 
           
            $( api.column( 3 ).footer() ).html(
                '$'+ColumnThreeTotal
            );

it has two problems, first it is showing of all rows instead of the current page, and second the results are coming as:

$1.000092378555231e+74  
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda