Showing
1 changed file
with
14 additions
and
0 deletions
@@ -293,6 +293,20 @@ class GetUtils { | @@ -293,6 +293,20 @@ class GetUtils { | ||
293 | /// Checks if num a EQUAL than num b. | 293 | /// Checks if num a EQUAL than num b. |
294 | static bool isEqual(num a, num b) => a == b; | 294 | static bool isEqual(num a, num b) => a == b; |
295 | 295 | ||
296 | + /// Checks if the cpf is valid. | ||
297 | + static bool isCpf(String cpf){ | ||
298 | + if (cpf == null) return false; | ||
299 | + | ||
300 | + // get only the numbers | ||
301 | + var numeros = cpf.replaceAll(RegExp(r'[^0-9]'), ''); | ||
302 | + // Test if the CPF has 11 digits | ||
303 | + if (numeros.length != 11) return false; | ||
304 | + // Test if all CPF digits are the same | ||
305 | + if (RegExp(r'^(\d)\1*$').hasMatch(numeros)) return false; | ||
306 | + | ||
307 | + return true; | ||
308 | + } | ||
309 | + | ||
296 | /// Capitalize each word inside string | 310 | /// Capitalize each word inside string |
297 | /// Example: your name => Your Name, your name => Your name | 311 | /// Example: your name => Your Name, your name => Your name |
298 | /// | 312 | /// |
-
Please register or login to post a comment