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

165
Visualizações
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 Respostas
Responde à pergunta

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 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