Useful satellite for validation user inputs proposes for any SwiftUI architectures. (MVVM as basic reference)
Firstly you should define the validation publisher within your @Published
property
class FormViewModel: ObservableObject {
@Published var email = ""
public lazy var emailValidator: ValidationPublisher = {
$email.validateWithRegex(
regex: RegularPattern.email,
error: "Not email",
tableName: nil
)
}()
}
Excellent! And then, call the validate view modifier from your SwiftUI Input
TextField("Should email", text: $viewModel.email)
.validate(for: viewModel.emailValidator)
Enjoy!
Same steps you can apply to SecureField
and Toggle
.
Useful set of validation publishers and regular expressions library. Validation for
The CombineValidate dependes on the Combine reactive framework. Minimal requirements:
Package installation occurs via SPM. Add package in your Xcode as dependency
Look at here and explore documentation.
link |
Stars: 19 |
Last commit: 1 year ago |
For now you can use validation more flexible
public lazy var emailValidator: ValidationPublisher = {
$person.map(\.email)
.validateWithRegex(
regex: RegularPattern.email,
error: "Not email",
tableName: nil
)
}()
makeRowWithIconAndPrefix(icon: "icon_facebook", prefix: "facebook.com/") {
TextField("Facebook", text: $viewModel.editedProfile.facebook)
}
.validate(for: viewModel.facebookValidator, configuration: .hintOnly)
Feel free to make your contribution!
Good luck!
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics