onlyNumberFrom8Positions static method
Implementation
static String onlyNumberFrom8Positions({required String text}) {
final regexp = RegExp(r'\D');
String onlyTextSanitized = text.replaceAll(regexp, '').trim();
switch (onlyTextSanitized.length) {
case 0:
onlyTextSanitized = '00000000';
break;
case 1:
onlyTextSanitized = '0000000$onlyTextSanitized';
break;
case 2:
onlyTextSanitized = '000000$onlyTextSanitized';
break;
case 3:
onlyTextSanitized = '00000$onlyTextSanitized';
break;
case 4:
onlyTextSanitized = '0000$onlyTextSanitized';
break;
case 5:
onlyTextSanitized = '000$onlyTextSanitized';
break;
case 6:
onlyTextSanitized = '00$onlyTextSanitized';
break;
case 7:
onlyTextSanitized = '0$onlyTextSanitized';
break;
case 8:
onlyTextSanitized = onlyTextSanitized;
break;
}
if (onlyTextSanitized.length > 8) {
onlyTextSanitized = onlyTextSanitized.substring(0, 8);
}
return onlyTextSanitized;
}