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

154
Visualizações
JavaScript phone number validation not throwing error for more than 10 digit

I implemented a logic that checks whether the phone number is valid. However, it's not checking if the number should be only 10 digits.

self.validateContactInfo = function () {
  let messages = [];
  let regex = '^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$';
  let phone = self.phone.peek();
  
  if (!phome && !phone.match(regex)) {
      messages.push("Please enter valid phone number");
   }
   
   if (messages.length != 0) {
        puDialogV2.showDialog($('.body-content'), "Error", messages, self, function () { return; });
        throw new Error(messages);
    }
  
}

 <div class="contactItem">\
                    <label style="padding:6px" >Home phone</label>\
                    <input class="form-control" type="text" data-bind="textInput: Phone" /> \
                    <div class="contactSms" data-bind="if: smsNotificationFeatureEnabled, css: { hasInfoPopup: !smsNotificationFeatureEnabled() }">\
                    </div>\
                </div>\

With the above code, if I leave the phone number field black or enter any alphabetic character, it throws an error. But If I enter 12 digit number it does not. For example, if I enter 71356878901212, it does not throw any error

about 4 years ago · Juan Pablo Isaza
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