Skip to content

Instantly share code, notes, and snippets.

@filipedfs
Created June 9, 2021 18:19
Show Gist options
  • Select an option

  • Save filipedfs/74022bb2006758b41053eee5858e03d7 to your computer and use it in GitHub Desktop.

Select an option

Save filipedfs/74022bb2006758b41053eee5858e03d7 to your computer and use it in GitHub Desktop.
Format CPF
void main() {
final String text = '11122233344';
print(maskText(text, 'CPF'));
}
String maskText(String text, String type) {
// Format CPF.
if (type == 'CPF') {
final List<String> chars = text.split('');
chars.insert(3, '.');
chars.insert(7, '.');
chars.insert(11, '-');
return chars.join('');
}
// Other number types.
else {
return text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment