Menu
Coddy logo textTech

Recap - Username Check

Part of the Logic & Flow section of Coddy's Swift journey — lesson 6 of 56.

challenge icon

Challenge

Medium

Read 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 3 and 16 characters (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