Skip to content

Instantly share code, notes, and snippets.

@gokmenbayram
Created February 22, 2022 10:06
Show Gist options
  • Save gokmenbayram/bb81805b4a82b275df658a33eec594f9 to your computer and use it in GitHub Desktop.
Save gokmenbayram/bb81805b4a82b275df658a33eec594f9 to your computer and use it in GitHub Desktop.
Password Regex Extension
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