SuperValidator is option-based validator for Swift.
To install via Pods just add this to your podfile.
pod 'SuperValidator', :git => 'https://github.com/tokopedia/ios-supervalidator.git'
To install via SPM just press '+' sign in Xcode list of packages and paste repo address: 'https://github.com/tokopedia/ios-supervalidator' into the search field and click Add Package
:
Return a boolean value
let validator = SuperValidator.shared
let url = "https://www.tokopedia.com/shop/test"
let isURL = validateURL(url, options: .init())
print(isURL) // true
With custom options. For detail explanation here.
let validator = SuperValidator.shared
let url = "https://www.tokopedia.com/shop/test"
let options = SuperValidator.Option.URL = .init(
protocols: ["https", "http"],
requireProtocol: true,
requireValidProtocol: true,
paths: ["/shop/{shopSlug}"],
allowQueryComponents: false,
domainWhitelist: [#"(www\.)?(tokopedia\.com)"#],
domainBlacklist: [],
fqdn: .init()
)
let isURL = validator.isURL(url, options: options)
print(isURL) // true
Return result success or error with reasons
let validator = SuperValidator.shared
let url = "https://www.tokopedia.com/shop/test"
let result = validateURL(url, options: .init())
switch result {
case let .failure(error):
switch error {
case .notUrl:
print("Please enter an url")
case .containsWhitespace:
print("Can't have whitespace")
case .containsQueryComponents:
print("Can't contains query components")
case .invalidProtocol:
print("Only allow HTTPS")
case .noProtocol:
print("Please provide protocol / scheme")
case .invalidPath:
print("Url path is invalid")
case .invalidDomain:
print("Wrong domain")
case .blacklistedDomain:
print("Domain not allowed")
case .invalidFQDN:
print("Enter a valid url")
}
case .success: break
}
If you want to discuss the SuperValidator or have a question about how to use it to solve your video player problem, you can start a topic in the issues tab of this repo
- Bind with TextField
- Bind with Rx
- More incoming validators
SuperValidator is written and maintaned by Tokopedia iOS Superman Squad. Alvin Matthew Pratama actively works to maintain SuperValidator. Thanks to Christopher Teddy Mienarto for helps creating email, phone number and more incoming validators.
This library is released under the Apache license. See LICENSE for details.