Created
March 15, 2023 19:10
-
-
Save MickhailP/1a732813dd41019579c8d8e6037808fb to your computer and use it in GitHub Desktop.
Email and password validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
var isValidEmail: Bool { | |
let emailFormat = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | |
let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailFormat) | |
return emailPredicate.evaluate(with: self) | |
} | |
var isValidPassword: Bool { | |
//Regex restricts to 8 character minimum, 1 capital letter, 1 lowercased letter, 1 number | |
let passwordFormat = "(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}" | |
let passwordPredicate = NSPredicate(format: "SELF MATCHES %@", passwordFormat) | |
return passwordPredicate.evaluate(with: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment