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

286
Visualizações
Using JavaScript reset removes format of phone field

I have 4 input fields for telephone numbers. They all have the [Phone] attribute in the model and the type="tel" in the HTML.

The fields look like this (904) 888-1234 when the form loads.

In model:

[Phone]
public string Phone {get;set;}

in HTML

<input type="tel" value="9048881234">
<button type="reset">reset</button>

When the user clicks the reset button, the formatting disappears (9048881234) and the form fails validation on submit.

Is there a way to reset the field so that it restores the format to (904) 888-1234?

Thanks,

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

0

Solution:

Before reset I store the field's value:

let phone = $("#Phone").val()

then clear it

$("#Phone").val("");

Then, after reset, I restore the value if it was not empty.

it (phone != ""){
    $("#Phone").val(phone);
}
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