Problem · String
Password Requirement Check
Learn this problemProblem statement
Given a string S, determine whether it is a valid password.
A password is valid exactly when all of these rules hold:
- Its length is at least
6. - It contains no space character.
- It contains at least one decimal digit.
- It contains at least one lowercase English letter.
- It contains at least one uppercase English letter.
- It contains at least one character from
!@#$%^&*()_.
Return true when every rule holds; otherwise, return false.
Function
solution(S: String) → booleanExamples
Example 1
S = "Ab1!cd"return = trueThe password has length six, contains every required character category, and contains no space.
Example 2
S = "Ab1 cd!"return = falseThe password contains a space, so it is invalid.
Constraints
0 <= S.length <= 100.- The allowed special-character set is exactly
!@#$%^&*()_.