Skip to content

Commit e2612ec

Browse files
andyboydYue-Wang-Google
authored andcommitted
Allows user to enter country code into phone number authentication field (E.g. by copy/pasting or from keyboard suggestions) (firebase#530)
Updates phone number validation to strip off the country code if it was duplicated in the actual phone number entry field
1 parent be1d20b commit e2612ec

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

FirebasePhoneAuthUI/FUIPhoneEntryViewController.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,16 @@ - (void)onNext:(NSString *)phoneNumber {
187187
[self incrementActivity];
188188
self.navigationItem.rightBarButtonItem.enabled = NO;
189189
FIRPhoneAuthProvider *provider = [FIRPhoneAuthProvider providerWithAuth:self.auth];
190-
NSString *phoneNumberWithCountryCode =
191-
[NSString stringWithFormat:@"+%@%@", _selectedCountryCode.dialCode, phoneNumber];
190+
NSString *selectedCountryCodeString =
191+
[NSString stringWithFormat:@"+%@", _selectedCountryCode.dialCode];
192+
BOOL isPhoneNumberAlreadyPrefixed = [phoneNumber hasPrefix:selectedCountryCodeString];
193+
NSString *phoneNumberWithCountryCode;
194+
if (isPhoneNumberAlreadyPrefixed) {
195+
phoneNumberWithCountryCode = phoneNumber;
196+
} else {
197+
phoneNumberWithCountryCode =
198+
[NSString stringWithFormat:@"%@%@", selectedCountryCodeString, phoneNumber];
199+
}
192200
[provider verifyPhoneNumber:phoneNumberWithCountryCode
193201
UIDelegate:self
194202
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {

0 commit comments

Comments
 (0)