No adaption required... It's a generic core-JS function and can be used as-is in a PDF form. If you want to use it as a validation script for a text field, place it as a doc-level script and then as the custom validation script of the field enter this code:
event.rc = validarCPF(event.value);