tracks/dart/exercises/phone-number/lib/example.dart in trackler-2.2.1.142 vs tracks/dart/exercises/phone-number/lib/example.dart in trackler-2.2.1.143
- old
+ new
@@ -1,8 +1,8 @@
class PhoneNumber {
/// Returns `String` for a valid number, `null` for invalid.
- dynamic cleanNumber(String phoneNumber) {
+ String clean(String phoneNumber) {
/// initialize an empty string.
String onlyDigits = "";
/// find all digits.
Iterable<Match> findDigits = new RegExp(r'\d+').allMatches(phoneNumber);
@@ -14,10 +14,10 @@
});
/// Only these special characters are allowed.
/// **"." "(" ")" "-" "+" ** and space,
/// remove these characters.
- phoneNumber = phoneNumber.replaceAll(new RegExp(r"^[\-\.\(\)\+\s+]*$"), "");
+ phoneNumber = phoneNumber.replaceAll(new RegExp(r"^[-.()+\s]*$"), "");
/// "123-@:!-7890" is invalid, however **"123-@:!-789012"** is valid
/// by the current logic since the regex grabs all the digits
/// but "123-@:!-78901256" should be considered as invalid.
/// hence if anything else still exists its an invalid number.