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

157
Vistas
Why does String(value).replace(/[^0-9.-]/g, '') work?

I saw String(value).replace(/[^0-9.-]/g, '') from a library that described to filter illegal characters, and finally it will return the legal number. Why does this work and what will really be replaced? I feel confused because I think nothing will be replaced.

For example:

String("1.absd").replace(/[^0-9.-]/g, '')
// '1.'
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

  1. String(value) will make string from value. So if you use number, this will convert it to string, because function replace is defined only from string.
  2. replace(/[^0-9.-]/g, '') this will replace any matching given regular expression with empty string. In regular expression you have [^0-9.-]. The ^ at start means, that any characters not from this interval will match. So any character other than number, dot or -. Modifier g after slash means, that this regular expression is global and will be applied for all matches

so from "1.absd" the characters "absd" will be replaced with empty string

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