コード例 #1
0
 public bool IsValidPhone(string phoneNumber)
 {
     try
     {
         return(_validationHelper.IsValidPhone(phoneNumber));
     }
     catch (Exception ex)
     {
         DependencyService.Get <IMetricsManagerService>().TrackException("PhoneValidationFailure", ex);
         return(false);
     }
 }
コード例 #2
0
        private async void SaveProfile()
        {
            // Check if any of the required fields are empty or invalid
            if (string.IsNullOrWhiteSpace(FirstName) ||
                string.IsNullOrWhiteSpace(LastName) ||
                string.IsNullOrWhiteSpace(Email) ||
                string.IsNullOrWhiteSpace(MobilePhone) ||
                (string.IsNullOrEmpty(Email) || !_validationHelper.IsValidEmail(Email)) ||
                (string.IsNullOrEmpty(MobilePhone) || !_validationHelper.IsValidPhone(MobilePhone)))
            {
                var @continue = await App.DisplayAlertAsync("Profile Incomplete", "The profile information is not complete - do you want to save anyway, or go back to correct it?", "Continue", "Cancel");

                if (!@continue)
                {
                    return;
                }
            }

            try
            {
                SaveButtonText = "Saving...";
                IsBusy         = true;
                SaveProfileCommand.ChangeCanExecute();
                DependencyService.Get <IMetricsManagerService>().TrackEvent("SaveVolunteer");
                await SurveyCloudService.SaveVolunteerAsync(UserSettings.Volunteer);

                SaveButtonText = "Saved!";
                UpdateCurrentInfo();
                IsBusy = false;
                SaveProfileCommand.ChangeCanExecute();
                await Task.Delay(SaveButtonMessageDelay);
            }
            catch (Exception ex)
            {
                DependencyService.Get <IMetricsManagerService>().TrackException("SaveVolunteerFailed", ex);
                await App.DisplayAlertAsync("Profile Save Error", "Failed to update profile information. Please try again later.", "OK");
            }
            finally
            {
                IsBusy = false;
                SaveProfileCommand.ChangeCanExecute();
                SaveButtonText = DefaultSaveButtonText;
            }
        }
コード例 #3
0
        private void HandleTextChanged(object sender, TextChangedEventArgs e)
        {
            var isValid = s_validationHelper.IsValidPhone(e.NewTextValue);

            ((Entry)sender).TextColor = isValid ? Color.Default : Color.Red;
        }