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

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

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