Swift is a new programming language that Apple announced last year. It is Apple’s answer to the Objective-C language that their company began developing in the 1980s. The main reason that Swift is so much more up to date than Objective-C is because Swift compiles to a machine language known as LLVM.
A day in the life of a web developer might include the following tasks: ✓ Create a new database table ✓ Write code in a swift app to save data from the database table ✓ Validate the values in the database table ✓ Add a custom field to the database table ✓ Create a form in swift using the form builder framework ✓ Add a save button to the form ✓ Add a custom field validator to the form ✓ Validate the values in the database table ✓ Add a validator to the form
Apple’s Swift programming language is a modern programming language that is very efficient and works great with iOS, OS X and watchOS. In this post we will create a simple “check if something is a number” custom field validator that will work with any swift project.
MIFieldValidator
The simplest approach to utilize a custom field validator is to use Field Validator. This is a clever class that allows you to validate fields with just one line of code. It’s a pretty clever code saver class for validating name, password, DOB, password change, email, phone number, and many other things…..
Techniques : 11
- static func isUserCanAbleToLogin(_ userName: String, _ password: String, _ isEmailLogin: Bool = true) -> Bool
- static func isValidData(_ validationModel: [ValidationModel]) -> Bool
- static func isMessageInRange(_ text: String?, _ charMaxLimit: Int, _ message: String) -> Bool
- static func changePassword(currentPassword: String, _ oldPassword: String, _ newPassword: String, _ confirmPassword: String) -> Bool
- static func checkPasswordsSame(_ password1: String, _ password2: String, _ isOldAndCurrent: Bool) -> Bool
- static func isMatchedPasswords(_ password: String?, _ cPassword: String?) -> Bool
- static func isValidPassword(_ text: String?, _ message: String?) -> Bool
- static func isValidMobileNumber(_ text: String?) -> Bool
- static func isValidEmail(_ text: String?) -> Bool
- static func isNotBlank(_ text: String?, _ message: String) -> Bool
- static func isDOB(_ minimumAge: Int = minAge, text: String?, date: Date?) -> Bool
Key features & Use
-
-
-
Check for required fields (such as FirstName, LastName, UserName, and so on) that are not empty.
-
-
EX:- Full Name Textfield -> txtFName:
[ValidationModel(validation:.notEmpty, value: txtFName.text, message: “Blank Full Name”)]) MIValidation.isValidData([ValidationModel(validation:.notEmpty, value: txtFName.text, message: “Blank Full Name”)]) MIValidation.isValidData([ValidationModel(validation-
-
-
Validate the Maximum Character Range of the Message
-
-
EX:- Full Name Textfield -> txtFName:
[ValidationModel(validation:.msgRange, value: txtFName.text, message: “Blank Full Name”)]) MIValidation.isValidData([ValidationModel(validation:.msgRange, value: txtFName.text, message: “Blank Full Name”)]) MIValidation.isValidData([ValidationModel(validationEX:- Email Textfield -> txtFEmail:
Return True or False using MIValidation.isValidEmail(txtFEmail.text).
EX:- PhoneNumber Textfield -> txtFPhoneNumber:
Return True or False with MIValidation.isValidMobileNumber(txtFPhoneNumber.text).
-
-
-
Validate your birthdate (Minimum Age Validation)
-
-
EX:- DOB Textfield -> txtFDOB:
[ValidationModel(validation:.dateOfBirth, value: txtFDOB.text, message: “Blank Date Of Birth”)]) MIValidation.isValidData([ValidationModel(validation:.dateOfBirth, value: txtFDOB.text, message: “Blank Date Of Birth”)]) MIValidation.isValidData([ValidationEX:- Password Textfield -> txtFPassword:
[ValidationModel(validation:.password, value: txtFDOB.text, message: “Blank Password”)]) MIValidation.isValidData([ValidationModel(validation:.password, value: txtFDOB.text, message: “Blank Password”)]) MIValidation.isValidData([ValidationModel(validation-
-
-
Examine Equality and Compare
-
-
EX:- New Password Textfield -> txtFNewPass and Confirm Password -> txtFCPass :
Return True Or False with MIValidation.checkPasswordsSame(txtFNewPass.text, txtFCPass.text)
-
-
-
Validate the Login Screen’s Credentials
-
-
EX:- Email Textfield -> txtFEmail and Password Textfield -> txtFPassword :
— Only use this MIValidation for login validation. isUserAbleToLoginIsUserAbleToLoginIsUserAbleTo (txtFEmail.text, txtFPassword.text) — Indicate whether the answer is True or False.
TextField Value – CurrentPassword = [email protected] is an example. – ConfirmPassword = txtFConfirmPassword – OldPassword = txtFOldPass – NewPassword = txtFNewPass
— Only use this MIValidation to change the password validation. returnTrue or False(currentPassword: “[email protected]”, txtFOldPass.text, txtFNewPass.text, txtFConfirmPass.text)
-
-
-
SignUp Validation using Standard Fields
-
-
Validation Array Look, for example
ValidationModel(validation:.msgRange, value: txtFName.text, message: “Blank Full Name”), ValidationModel(validation:.email, value: txtFEmailAddress.text, message: “Blank Email Address”), ValidationModel(validation:.mobileNumber, value: txtFMobileNumber.text, message: “Blank Phone Number”), ValidationModel(validation: — Call Only This MIValidation.isValidData(arrValidationModel) For Sign Up Validation — Return True or False
Implementation
Requirements
GitHub
https://github.com/Mindinventory/MIFieldValidator
Related Tags:
swiftui form validationios form validation best practicesswift validate email text fieldtextfield validation in swiftswift validation rulesuitextfield validation error message swift,People also search for,Privacy settings,How Search works,uitextfield validation error message swift,show error icon automatically in uitextfield when validation is failed in swift,swiftui form validation,how to create registration form in ios swift,ios form validation best practices,swift validate email text field,textfield validation in swift,swift validation rules