6
The function below tests the input of a Cpf, (typing or gluing) whose format should be ###.###.###-##
If the input consists only of numbers without separators, or some separator is missing, for example ###.########
how can I make value
input is converted to valid format.
is not CPF validation but pure formatting!!!
function ValidaCPF(){
var ao_cpf=document.forms.form1.ao_cpf.value;
var cpfValido = /^(([0-9]{3}.[0-9]{3}.[0-9]{3}-[0-9]{2}))$/;
if (cpfValido.test(ao_cpf) == false) {
//alert("invalido");
var valorValido = document.getElementById("ao_cpf").value = "???????";
}
}
<form name="form1">
<input type="text" name="ao_cpf" id="ao_cpf" placeholder="CPF" maxlength="14" OnBlur="ValidaCPF();"/>
</form>
I’ll illustrate with numbers to be clear
on entering
11111111111
return me to input111.111.111-11
on entering
111.11111111
return me to input111.111.111-11
on entering
111.111111-11
return me to input111.111.111-11
etc....
you want to validate the amount of numbers tbm?
– guijob