05-17-2019 03:49 PM - edited 05-17-2019 03:56 PM
Hi,
Please, could anyone help me?
I am creating a Guest Portal and according to Law we need to store the data of the user (Name, Phone, Email and CPF).
CPF (represents the ID of the Brazilian identity document) in format "999.999.999-99". I've created a new custom field for this.
However, to verify that the identity document is valid or invalid there is a javascript algorithm for validation.
I need help to do the validation of this custom field called CPF with some javascript. I do not know how to make the javascript call on CISCO ISE.
Links with the Javascript of validation of the CPF.
Script validation CPF https://www.geradorcpf.com/javascript-validar-cpf.htm
Test validation CPF https://www.geradorcpf.com/validar-cpf.htm
Mask JQuery https://www.geradorcpf.com/mascara-cpf-com-jquery.htm
On the internet there are other sites with the CPF validation algorithm
Thank you very much
Mauricio Pissinati
PS - I had made another Post, but when editing something went wrong and so I created this new post.
Solved! Go to Solution.
08-14-2020 02:39 PM
Hi everyone
Same problem here, the script works but only garantee that people type numbers, but how I can prove that people its type the correct information?
I must garantee that UserX have CPF valid
any news about it?
04-18-2025 06:57 AM
Version working on 3.2 p7:
<script>
setTimeout(function() {
// Add CPF validation method using jQuery validator
$.validator.addMethod("validaCPF", function(value, element) {
value = value.replace(/\D/g, ''); // Remove non-numeric characters
var Soma;
var Resto;
Soma = 0;
if (value == "00000000000") return false; // Check for invalid CPF (e.g., 000.000.000-00)
if (value == "11111111111") return false; // Check for invalid CPF (e.g., 111.111.111-11)
if (value == "22222222222") return false; // Check for invalid CPF (e.g., 222.222.222-22)
if (value == "33333333333") return false; // Check for invalid CPF (e.g., 333.333.333-33)
if (value == "44444444444") return false; // Check for invalid CPF (e.g., 444.444.444-44)
if (value == "55555555555") return false; // Check for invalid CPF (e.g., 555.555.555-55)
if (value == "66666666666") return false; // Check for invalid CPF (e.g., 666.666.666-66)
if (value == "77777777777") return false; // Check for invalid CPF (e.g., 777.777.777-77)
if (value == "88888888888") return false; // Check for invalid CPF (e.g., 888.888.888-88)
if (value == "99999999999") return false; // Check for invalid CPF (e.g., 999.999.999-99)
// CPF first check digit
for (i = 1; i <= 9; i++) Soma = Soma + parseInt(value.substring(i - 1, i)) * (11 - i);
Resto = (Soma * 10) % 11;
if ((Resto == 10) || (Resto == 11)) Resto = 0;
if (Resto != parseInt(value.substring(9, 10))) return false;
// CPF second check digit
Soma = 0;
for (i = 1; i <= 10; i++) Soma = Soma + parseInt(value.substring(i - 1, i)) * (12 - i);
Resto = (Soma * 10) % 11;
if ((Resto == 10) || (Resto == 11)) Resto = 0;
if (Resto != parseInt(value.substring(10, 11))) return false;
return true;
}, 'Coloque um CPF válido.');
// Apply CPF validation to the field
jQuery("#guestUser\\.fieldValues\\.ui_cpf_text").rules("add", { validaCPF: true });
// CPF Formatting: Apply mask as XXX.XXX.XXX-XX
$("#guestUser\\.fieldValues\\.ui_cpf_text").on("input", function() {
if ($(this).val().length > 14) {
$(this).val($(this).val().substring(0, 14)); // Limit length to 14 (XXX.XXX.XXX-XX format)
}
let value = $(this).val().replace(/[^0-9]/g, "")
.replace(/^([\d]{3})([\d]{3})?([\d]{3})?([\d]{2})?/, "$1.$2.$3-$4");
$(this).val(value); // Apply formatted value
});
// Phone Validation: Phone number format (XXX) XXXXX-XXXX
jQuery("#guestUser\\.fieldValues\\.ui_phone_number").attr("placeholder", "(XX)9XXXX-XXXX");
jQuery("#guestUser\\.fieldValues\\.ui_phone_number").attr("type", "number");
setTimeout(function(){
cisco.ise.validation.setPhoneRegex (/^\(?(\d{2})\)?(\d{5})[- ]?(\d{4})$/);
cisco.ise.validation.setPhoneNumberMessage("Informe seu numero de celular (XX)9XXXX-XXXX");
});
// Form submission handler
$("#selfRegForm").validate({
rules: {
"#guestUser\\.fieldValues\\.ui_cpf_text": {
required: true,
validaCPF: true
},
"#guestUser\\.fieldValues\\.ui_phone_number": {
required: true,
minlength: 14, // Minimum length for phone number (formatted as (XX) XXXXX-XXXX)
maxlength: 14
}
},
messages: {
"#guestUser\\.fieldValues\\.ui_cpf_text": {
required: "Por favor, CPF requerido. Insira seu CPF.",
validaCPF: "Por favor, CPF inválido. insira um CPF válido."
},
"#guestUser\\.fieldValues\\.ui_phone_number": {
required: "Por favor, telefone requerido. Insira um número de telefone.",
minlength: "Por favor, insira um número de caracteres maior de telefone para ser válido.",
maxlength: "Por favor, insira um número de caracteres menor de telefone para ser válido"
}
},
// If validation fails, prevent form submission
submitHandler: function(form) {
form.submit(); // Submit the form if all fields are valid
}
});
}, 50);
</script>
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide