summaryrefslogtreecommitdiff
path: root/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
diff options
context:
space:
mode:
Diffstat (limited to 'libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java')
-rw-r--r--libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java6
1 files changed, 4 insertions, 2 deletions
diff --git a/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java b/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
index c9a1f5c3..be11be57 100644
--- a/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
+++ b/libphonenumber/src/com/google/i18n/phonenumbers/AsYouTypeFormatter.java
@@ -70,10 +70,12 @@ public class AsYouTypeFormatter {
// used by the AYTF. It is eligible when the format element under numberFormat contains groups of
// the dollar sign followed by a single digit, separated by valid phone number punctuation. This
// prevents invalid punctuation (such as the star sign in Israeli star numbers) getting into the
- // output of the AYTF.
+ // output of the AYTF. We require that the first group is present in the output pattern to ensure
+ // no data is lost while formatting; when we format as you type, this should always be the case.
private static final Pattern ELIGIBLE_FORMAT_PATTERN =
Pattern.compile("[" + PhoneNumberUtil.VALID_PUNCTUATION + "]*"
- + "(\\$\\d" + "[" + PhoneNumberUtil.VALID_PUNCTUATION + "]*)+");
+ + "\\$1" + "[" + PhoneNumberUtil.VALID_PUNCTUATION + "]*(\\$\\d"
+ + "[" + PhoneNumberUtil.VALID_PUNCTUATION + "]*)*");
// A set of characters that, if found in a national prefix formatting rules, are an indicator to
// us that we should separate the national prefix from the number when formatting.
private static final Pattern NATIONAL_PREFIX_SEPARATORS_PATTERN = Pattern.compile("[- ]");