Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda