Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public static bool CepValidator(string cep)

public static bool CpfValidator(string cpf)
{
if (string.IsNullOrEmpty(cpf)) {
if (string.IsNullOrEmpty(cpf))
return false;
}

cpf = cpf.Replace(".", "").Replace("-", "");
cpf = cpf.Trim();
Expand All @@ -39,7 +38,14 @@ public static bool CpfValidator(string cpf)
soma = 0;

for (int i = 0; i < 9; i++)
soma += int.Parse(tempCpf[i].ToString()) * multiplicador1[i];
{
int digit;

if (int.TryParse(tempCpf[i].ToString(), out digit))
soma += digit * multiplicador1[i];
else
return false;
}
resto = soma % 11;
if (resto < 2)
resto = 0;
Expand All @@ -49,7 +55,13 @@ public static bool CpfValidator(string cpf)
tempCpf = tempCpf + digito;
soma = 0;
for (int i = 0; i < 10; i++)
soma += int.Parse(tempCpf[i].ToString()) * multiplicador2[i];
{
int digit;
if (int.TryParse(tempCpf[i].ToString(), out digit))
soma += digit * multiplicador2[i];
else
return false;
}
resto = soma % 11;
if (resto < 2)
resto = 0;
Expand Down