How do I lock my screen when typing an invalid CPF?

Asked

Viewed 48 times

0

I have a modal to type my CPF, but even if I put an invalid CPF and click the forward button it jumps to the next screen, I wanted to jump to the next screen only when the CPF is valid

function CadastrarPessoa() {
    debugger
    var url = '';
    $.ajax({
        type: 'POST',
        url: "/Pessoa/VerificarUrl",
        data: {},

        success: function (data) {
            if (data == true) {
                //OpenModal('modal', '/Pessoa/AdicionarCliente');
                location.href = "/Pessoa/ClienteAlegriaCard";
            }
            else {
                debugger
                url = $("#VerificaCPF").val().length == 14 ? '/Pessoa/AdicionarPF' : '/Pessoa/AdicionarPJ'
                location.href = url
            }
        }

    });
}




$(document).on('focusout', '#VerificaCPF', function () {
    var cpf = $("#VerificaCPF").val();

    if (cpf.length >= 14) {

        $.ajax({
            url: '/Pessoa/VerificaCpf/?cpf=' + cpf,
            type: 'POST',
            data: { cpf: cpf },
            async: false,
            success: function (data) {
                if (data != false) {
                    if (data.IsFornecedor == false) {
                        $.ajax({
                            type: 'POST',
                            url: "/Pessoa/VerificarUrl",
                            data: {},
                            success: function (_data) {
                                if (_data == true) {
                                    $('#btnprx').attr('onclick', 'EditarClienteAlegriaCard(' + data.Id + ');');
                                }
                                else {
                                    $('#btnprx').attr('onclick', 'EditarPessoa(' + data.Id + ');');
                                }
                            }

                        });
                        $("#AdicionarNovo").hide();
                        $("#HasCliente").show()
                        $("#Nome").val(data.NmPessoa);
                        $("#Telefone").val(data.NuFone);
                        $("#Email").val(data.Email);
                    }
                    else {
                        $('#btnprx').attr('onclick', 'CadatrarPessoa();');
                        $("#AdicionarNovo").hide();
                        $("#HasCliente").hide()
                        $("#Nome").val("");
                        $("#Telefone").val("");
                        $("#Email").val("");

                        noty({
                            text: "Cpf/Cnpj informado já possui cadastro de fornecedor!",
                            type: 'warning',
                            timeout: 3000,
                            layout: 'center'
                        });
                    }
                }
                else {
                    $("#HasCliente").hide()
                    $("#AdicionarNovo").show();
                }
            }
        });
    }
});
  • just disable the button, use a function that validates, can be in the keypress field and enable the button when it is ok

  • I can do this all by javascript?

  • 1

    can yes... take advantage and see this question that has a validation function that can be used to validate Cpf: https://answall.com/q/51340/57220 the vc button can make a $('#idDoBotao').attr('disabled','disabled') to disable, and to enable again remove the attribute: $('#idDoBotao').attr('disabled',''), can be done with prop(), but anyway that’s basically it

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.