UITextField Validator is a UITextField validator which can be use in different ways. So you would now focus on writing your core logic and let UITextFieldValidator handle all your field validations. For more info you can see "How to use" section bellow.
To run the example project, clone the repo, and run pod install
from the Example directory first.
UITextField Validator is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'UITextFieldValidator'
Deployment Target should be 11.0
The validator check ContentType
of your UITextField and according to ContentType
it will validate text fields if ContentType
is not set for your text field then it will validate according to your KeyboardType
. All this take care by this lib.
import UITextFieldValidator
There are two version of validation here, one is for simple validation and second one is validation with range. Range validation will take two more input for minimum characters and the maximum characters
You can pass multiple UITextField in both methods.
Validator.shareInstance.textFieldValidator(textField: TextField_1,TextField_2,TextField_3...TextField_n) { (textField:UITextField, isSuccess) in
//handle result here
}
Validator.shareInstance.textFieldValidator(withRange: (textField: TextField_1,TextField_2,TextField_3...TextField_n, minRange: 1, maxRange: 50)) { (textField:UITextField, isSuccess) in
//handle result here
}
Note : When all textfields will be validated successfully then textfield will return nil else there will be a textfield which is not validated.
yourView is the view which contains all your UITextField which need to be validated
Validator.shareInstance.validate(withView: yourView) { (textFields: [UITextField]?, isValidated) in
if isValidated {
//[UITextField]? will be nil
print("valid field")
}else{
print("not valid field")
//[UITextField]? will contain all the non validated UITextFields
}
}
UITextFieldValidator is available under the MIT license. See the LICENSE file for more info.