Created
February 22, 2022 10:06
-
-
Save gokmenbayram/bb81805b4a82b275df658a33eec594f9 to your computer and use it in GitHub Desktop.
Password Regex Extension
This file contains hidden or 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
private val passwordRegex = Pattern.compile("^" + | |
"(?=.*[0-9])" + // En az bir rakam | |
"(?=.*[a-z])" + // En az bir küçük harf | |
"(?=.*[A-Z])" + // En az bir büyük harf | |
"(?=.*[a-zA-Z])" + // Herhangi bir harf | |
"(?=.*[@#$%^&+=])" + // En az bir özel karakter | |
"(?=\\S+$)" + // Boşluk yok | |
".{8,}" + // En az 8 karakter | |
"$") | |
fun String.checkPassword(): Boolean { | |
return passwordRegex.matcher(this).matches() | |
} | |
fun main() { | |
val password = "Gokmen@52" // Valid password | |
val invalidPassword = "Gokm en" // invalid password | |
println("${password.checkPassword()}") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment