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

249
Vistas
country code will automatically added before mobile number

If any one type in input box only number like : 01234567890 (total 13 digit with country code) then automatically add 88 before mobile number but if if anyone number with 8801234567890 it wont added before number. Another one if type 1234567890 total 10 digit then add 880 before number. how to fix it? I tried with add value but its not working. I need only my conditions not every time.

$(document).ready(function() {

    $('#phone').keyup(function() {
        let total_length = this.value.length;
        
        if(total_length='11'){
          $("#phone").val("88"+$("#phone").val());
        }
        else if(total_length='10'){
          $("#phone").val("880"+$("#phone").val());
        }
        else{
           $("#phone").val();
        }
    });

    $.validator.addMethod("countryValid", function(value, element) {
        return this.optional(element) || /^(?:\+88|88)?(01[3-9]\d{8})$/i.test(value);
      }, "Please enter valid phone no."); 

  
    $("#my_form").validate({
        rules: {
        phone : {
            required: true,
            number: true,
            countryValid: true
        }
        }
    });

  });
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js"></script>

<form id="my_form">

<input type="text" name="phone" id="phone" />
<br><br>
<button type="submit">Submit</button>

</form>

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

0

Fixed it with replace keyup to change and add the ==(Equal to) from =(assignment operators)

$('#phone').change(function() {
        let total_length = this.value.length;
        
        if(total_length=='11'){
          $("#phone").val("88"+$("#phone").val());
        }
        else if(total_length=='10'){
          $("#phone").val("880"+$("#phone").val());
        }
        else{
           $("#phone").val();
        }
    });

Thanks @CherryDT for this help.

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