Why does the following regex expression in kotlin does not validate special characters? What constitutes as special character?
private fun validateSpecialCharacter(password: String): Boolean =
password.matches(Regex("[!@#\$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]"))
>Solution :
Using CharSequence.matches(regex) returns True if the entire string matches the regex. Given your code, it looks as if you want your function to return True as long as there is an occurrence matching the regex.
Using CharSequence.contains(regex) instead should yield your desired results. Your code becomes:
private fun validateSpecialCharacter(password: String): Boolean =
password.contains(Regex("[!@#\$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]"))