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

160
Vistas
Formatting an document input field that shows automatically dots and hyphens but not allowing them when submitting the form

I'm currently working in user creation login page for an e-commerce and I need to achieve something like this: https://drive.google.com/file/d/1JJBeZG-oyzrh8vCDRMjfv03oGDjrWwZw/view?usp=sharing (The video has to be seen on fullscreen, otherwise it'll be too small to detail anything)

Thing is I should not allow any special characters when the form is submitted and I think I already solved that:

$('#login_form #document').on('input', function() {
  this.value = this.value.toLocaleUpperCase();
  let count = this.selectionStart,
      regex = /[^a-z0-9]/gi,
      value = $(this).val();
      console.log(value)
  if(regex.test(value)) {
    $(this).val(value.replace(regex, ''));
    count--;
  }

  this.setSelectionRange(count, count);
});

But I can't really think in a way to show the dots and hyphens and not allowing them on submit.

Also, any recommendation to improve the code will be well receive. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Just keep the formatting from your front-end, do some reverse reformatting in backend instead, example you input 10,000.00 then you submit it using backend PHP just replace "," str_replace(',', '', '10,000.00') then you will get 10000.00 then use $new_number = (float)10000.00

$input_number = '10,000.00';
$input_number_no_comma =  str_replace(',', '', $input_number);
$input_number_new = (float)$input_number_no_comma;

echo $input_number_new ;
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