Recap - Username Check
Part of the Logic & Flow section of Coddy's Swift journey — lesson 6 of 56.
Challenge
MediumRead a single line of input: a candidate username. A username is valid when, after trimming whitespace at both ends and lowercasing, all of the following hold:
- Its length is between
3and16characters (inclusive) - It contains no spaces (after trimming)
- It does not start with a digit
- It does not contain
!,?, or.
Print ok: <cleaned> when valid (where cleaned is the trimmed, lower-cased version), otherwise bad.
For input Alice42 , the output is ok: alice42.
Try it yourself
let line = readLine()!
// TODO: trim, lowercase, validate length / spaces / edges / forbidden chars
All lessons in Logic & Flow
1Strings In Depth
Count and IndicesCase and TrimSearching in StringsSplitting and JoiningReplacing SubstringsRecap - Username Check