Is there a way to get an unmasked value
codegrue opened this issue · comments
CodeGrue commented
For example -
mask: (000) 000-0000
value: (123) 456-7890
unmaskedValue: 123456789
??
CodeGrue commented
Not sure if the best way but this code will strip off the mask:
import 'dart:math';
void main() {
String mask = 'AA (000) @@@-@@@@ **';
String maskedValue = 'US (555) 123-CALL #';
print(unmaskValue(mask, maskedValue));
// prints US555123CALL#
}
String unmaskValue(String mask, String maskedValue) {
String specialCharacters = '0A@*';
String unmaskedValue = '';
for (int i=0; i < min(mask.length, maskedValue.length); i++) {
if (specialCharacters.contains(mask[i]))
unmaskedValue += maskedValue[i];
}
return unmaskedValue;
}
Calebe Oliveira commented
"one liner" solution:
var unmaskedPhone = _phone.replaceAll(new RegExp('[^0-9]'), '');
warning: this replaceAll
approach may fail in complex cases.
Emerson Siega commented
Will be very good if there's a rawText
method in the future.
rafaelmota commented
How Get unmasked text?
Andy D. Nguyen commented
Will we do it sir :D?