diff --git a/InAppSettingsKit.podspec b/InAppSettingsKit.podspec index 0ef71b2a..3fb2560f 100644 --- a/InAppSettingsKit.podspec +++ b/InAppSettingsKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'InAppSettingsKit' - s.version = '3.8.2' + s.version = '3.8.3' s.summary = 'This iPhone framework allows settings to be in-app in addition to being in the Settings app.' s.description = <<-DESC diff --git a/InAppSettingsKitSampleApp/Classes/MainViewController.swift b/InAppSettingsKitSampleApp/Classes/MainViewController.swift index 6cedd7b3..ee6cfb03 100644 --- a/InAppSettingsKitSampleApp/Classes/MainViewController.swift +++ b/InAppSettingsKitSampleApp/Classes/MainViewController.swift @@ -91,6 +91,22 @@ extension MainViewController: IASKSettingsDelegate { } textField.textColor = .red return .failed + } else if key == "account_name", let value = textField.text { + let regex = "^@?[\\w](?!.*?\\.{2})[\\w.]{1,28}[\\w]$" + if value.isEmpty { + return .ok + } else if value == "@" { + replacement?.pointee = "" as NSString + return .failed + } else if value.range(of: regex, options: .regularExpression) == nil { + if let previousValue { + replacement?.pointee = previousValue as NSString + return .failedWithShake + } + } else if !value.hasPrefix("@") { + replacement?.pointee = "@\(value)" as NSString + return .okWithReplacement + } } return .ok } diff --git a/InAppSettingsKitSampleApp/Settings.bundle/Complete.plist b/InAppSettingsKitSampleApp/Settings.bundle/Complete.plist index 9e6e5998..78bd282b 100644 --- a/InAppSettingsKitSampleApp/Settings.bundle/Complete.plist +++ b/InAppSettingsKitSampleApp/Settings.bundle/Complete.plist @@ -304,6 +304,18 @@ IASKCellImage mail + + Type + PSTextFieldSpecifier + Title + Account + Key + account_name + AutocorrectionType + No + IASKCellImage + person.crop.circle + Type PSGroupSpecifier diff --git a/Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m b/Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m index 46e06504..2f2bb083 100644 --- a/Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m +++ b/Sources/InAppSettingsKit/Controllers/IASKAppSettingsViewController.m @@ -1204,6 +1204,9 @@ - (void)textFieldDidEndEditing:(IASKTextField *)textField { }; switch (result) { + case IASKValidationResultOkWithReplacement: + restoreText(); + // fallthrough case IASKValidationResultOk: { if (![self.settingsStore objectForSpecifier:specifier] && textField.text.length == 0) { return; diff --git a/Sources/InAppSettingsKit/include/IASKAppSettingsViewController.h b/Sources/InAppSettingsKit/include/IASKAppSettingsViewController.h index f7b89fb2..494d483e 100644 --- a/Sources/InAppSettingsKit/include/IASKAppSettingsViewController.h +++ b/Sources/InAppSettingsKit/include/IASKAppSettingsViewController.h @@ -176,8 +176,16 @@ shouldPresentMailComposeViewController:(MFMailComposeViewController*)mailCompose #pragma mark - Validation typedef NS_ENUM(NSUInteger, IASKValidationResult) { + /** validation is OK, no replacement is performed. */ IASKValidationResultOk, + + /** validation is OK with the replacement performed. */ + IASKValidationResultOkWithReplacement, + + /** validation has failed, the replacement is performed. */ IASKValidationResultFailed, + + /** validation has failed, the replacement is performed, and the field shakes to indicate the error. */ IASKValidationResultFailedWithShake, }; /** validate user input in text fields