// Import
import SValidator
// Add A Validation
let svalidator = ASValidator()
textField.register(svalidator: validator, defaultErrorMsg: nil, rules: [ASVRequiredRule(nil), ASVMinLengthRule(2), ASVMaxLengthRule(5, nil)])
// Validation Check
let validate = asValidator.apply()
if let validate = validate, validate.isValid() {
// MARK: - Validation Success
}else{
// MARK: - Validation Fail
}
textField.addField(svalidator: svalidator, defaultErrorMsg: nil, rules: [ASVRequiredRule(errorMsg: nil)])
extension UITextField {
func addField(svalidator: ASValidator?, defaultErrorMsg: String?, rules: [ASVRule]?) {
register(
svalidator: svalidator,
field: self,
errorLabel: nil,
errorBorderView: self,
errorBorderColor: .red,
normalBorderColor: .gray,
defaultErrorMsg: defaultErrorMsg,
borderWidth: 1.0,
rules: rules
)
}
}
ASVRequiredRule(nil)
ASVMinLengthRule(2)
ASVMaxLengthRule(5, nil)
...
ASValidator is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ASValidator'
Amit Mondol, amitpstu1@gmail.com
ASValidator is available under the MIT license. See the LICENSE file for more info.