Last active
April 23, 2024 04:29
-
-
Save sourleangchhean168/ae77c0d95a29128e7a899f732197a233 to your computer and use it in GitHub Desktop.
Check Valid Password
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
func isValidPassword(password: String) -> Bool { | |
// define validation rules here | |
let passwordRegEx = "(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}" | |
let passwordPred = NSPredicate(format: "SELF MATCHES %@", passwordRegEx) | |
return passwordPred.evaluate(with: password) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use the
isValidPassword(password:)
function:Example Usage:
Checking Password Validity:
Validating User Input:
Displaying a Password Strength Indicator:
Explanation:
isValidPassword(password:)
function checks if a password meets certain validation rules, such as containing at least one uppercase letter, one lowercase letter, one digit, and being at least 8 characters long.By using the
isValidPassword(password:)
function, you can ensure that passwords entered by users meet certain security requirements, and provide feedback on password strength or validity.