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

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