Validate field and configure label errors
-
Hi.
I need to create a custom validation for a field called ‘billing_cpf’. I managed to do it through a Jquery script. What I need now is to make the error message appear as shown in the attached image.I also attach the code I used for validation.
function calculacpf() { if (is_page('Criar conta')) { wc_enqueue_js( " $(function() { //Executa a requisição quando o campo username perder o foco $('#billing_cpf').blur(function() { var cpf = $('#billing_cpf').val().replace(/[^0-9]/g, '').toString(); if( cpf.length == 11 ) { var v = []; //Calcula o primeiro dígito de verificação. v[0] = 1 * cpf[0] + 2 * cpf[1] + 3 * cpf[2]; v[0] += 4 * cpf[3] + 5 * cpf[4] + 6 * cpf[5]; v[0] += 7 * cpf[6] + 8 * cpf[7] + 9 * cpf[8]; v[0] = v[0] % 11; v[0] = v[0] % 10; //Calcula o segundo dígito de verificação. v[1] = 1 * cpf[1] + 2 * cpf[2] + 3 * cpf[3]; v[1] += 4 * cpf[4] + 5 * cpf[5] + 6 * cpf[6]; v[1] += 7 * cpf[7] + 8 * cpf[8] + 9 * v[0]; v[1] = v[1] % 11; v[1] = v[1] % 10; //Retorna Verdadeiro se os dígitos de verificação são os esperados. if ( (v[0] != cpf[9]) || (v[1] != cpf[10]) ) { $('#billing_cpf').val(''); $('#billing_cpf').focus(); } } else { $('#billing_cpf').val(''); $('#billing_cpf').focus(); } }); }); "); } } add_action( 'wp_enqueue_scripts', 'calculacpf' , 10);
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
The topic ‘Validate field and configure label errors’ is closed to new replies.