Back to the Problem
Length check, first-character check, then per-character class check.
Complexity: O(|S|)