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

225
Visualizações
How can i remove zero from input number in form javascript?

I have this code and I want to remove first zero from phone number.

mobile = $('#country_code').val();
        mobile += input.val();

Country code is: 966

Phone input is: 055642444

And output in this code is: 966055642444

I want it to be 96655642444 without zero after country code.

Thanks

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Have you tried parseInt(), integers don't have leading 0s - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt

mobile = $('#country_code').val();
        mobile += parseInt(input.val());
about 4 years ago · Juan Pablo Isaza Relatório

0

You can use substring to remove the first N characters from a string.

First of all, assign a variable with the value of input.val()

let str = input.val()

Now, you can index the Nth element of str and check its value:

if (str[0] === "0") str = str.substring(1)

With this, you have successfully checked if the first character is "0" and reassigned the str variable accordingly.

about 4 years ago · Juan Pablo Isaza Relatório

0

For this, I'd use substring which returns a new string. Example :

mobile = '0652447766';
mobile = mobile.substring(1)
console.log('mobile = ', mobile)

>> mobile = '652447766'

Warning ! Calling mobile.substring() doesn't actually modify mobile ! Strings are immutable in Js, so you'll have to get the returned value of substring() with mobile = mobile.substring(1)

Hope it helped !

about 4 years ago · Juan Pablo Isaza Relatório
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