Problem · String

Password Requirement Check

Learn this problem
EasyDRW logoDRWFULLTIMEOA

Problem 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) → boolean

Examples

Example 1

S = "Ab1!cd"return = true

The password has length six, contains every required character category, and contains no space.

Example 2

S = "Ab1 cd!"return = false

The password contains a space, so it is invalid.

Constraints

  • 0 <= S.length <= 100.
  • The allowed special-character set is exactly !@#$%^&*()_.

More DRW problems

drafts saved locally
public boolean solution(String S) {
    // Write your code here.
}
S"Ab1!cd"
expectedtrue
checking account