Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Nipodemos
2020-07-06 17:30:31 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8b418ac87c8d1dc05d3770c64a0e16212de58d7b
8b418ac8
1 parent
03c3a65b
make code & comments english
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
lib/src/regex/get_utils.dart
lib/src/regex/get_utils.dart
View file @
8b418ac
...
...
@@ -294,44 +294,44 @@ class GetUtils {
static
bool
isEqual
(
num
a
,
num
b
)
=>
a
==
b
;
/// Checks if the cpf is valid.
static
bool
isCpf
(
String
cpf
){
static
bool
isCpf
(
String
cpf
)
{
if
(
cpf
==
null
)
return
false
;
// get only the numbers
var
num
ero
s
=
cpf
.
replaceAll
(
RegExp
(
r'[^0-9]'
),
''
);
var
num
ber
s
=
cpf
.
replaceAll
(
RegExp
(
r'[^0-9]'
),
''
);
// Test if the CPF has 11 digits
if
(
num
ero
s
.
length
!=
11
)
return
false
;
if
(
num
ber
s
.
length
!=
11
)
return
false
;
// Test if all CPF digits are the same
if
(
RegExp
(
r'^(\d)\1*$'
).
hasMatch
(
num
ero
s
))
return
false
;
if
(
RegExp
(
r'^(\d)\1*$'
).
hasMatch
(
num
ber
s
))
return
false
;
// Dividir dígitos
List
<
int
>
digitos
=
numeros
.
split
(
''
).
map
((
String
d
)
=>
int
.
parse
(
d
)).
toList
();
// split the digits
List
<
int
>
digits
=
numbers
.
split
(
''
).
map
((
String
d
)
=>
int
.
parse
(
d
)).
toList
();
// Calcular o primeiro dígito verificador
var
calc_dv1
=
0
;
// Calculate the first verifier digit
var
calcDv1
=
0
;
for
(
var
i
in
Iterable
<
int
>.
generate
(
9
,
(
i
)
=>
10
-
i
))
{
calc
_dv1
+=
digito
s
[
10
-
i
]
*
i
;
calc
Dv1
+=
digit
s
[
10
-
i
]
*
i
;
}
calc_dv1
%=
11
;
var
dv1
=
calc_dv1
<
2
?
0
:
11
-
calc_dv1
;
calcDv1
%=
11
;
var
dv1
=
calcDv1
<
2
?
0
:
11
-
calcDv1
;
// Testar o primeiro dígito verificado
if
(
digitos
[
9
]
!=
dv1
)
return
false
;
// Tests the first verifier digit
if
(
digits
[
9
]
!=
dv1
)
return
false
;
// Calcular o segundo dígito verificador
var
calc_dv2
=
0
;
// Calculate the second verifier digit
var
calcDv2
=
0
;
for
(
var
i
in
Iterable
<
int
>.
generate
(
10
,
(
i
)
=>
11
-
i
))
{
calc
_dv2
+=
digito
s
[
11
-
i
]
*
i
;
calc
Dv2
+=
digit
s
[
11
-
i
]
*
i
;
}
calc
_d
v2
%=
11
;
calc
D
v2
%=
11
;
var
dv2
=
calc_dv2
<
2
?
0
:
11
-
calc_dv2
;
// Testar o segundo dígito verificador
if
(
digitos
[
10
]
!=
dv2
)
return
false
;
var
dv2
=
calcDv2
<
2
?
0
:
11
-
calcDv2
;
return
true
;
// Test the second verifier digit
if
(
digits
[
10
]
!=
dv2
)
return
false
;
return
true
;
}
/// Capitalize each word inside string
...
...
Please
register
or
login
to post a comment