Skip to main content

HTML Form Validation — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the HTML Form Validation lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Require a field

    easy10 min

    Make the email field required.

  2. 2

    Validate with a pattern

    easy10 min

    Require a 5-digit code using pattern.

  3. 3

    Set a minimum

    easy10 min

    Require a number of at least 1.

  4. 4

    Set a maximum

    easy10 min

    Cap the number at 10.

  5. 5

    Combine validation rules

    medium10 min

    Require an email field with a minimum length.

Find the bug(5)

  1. 1

    Fix validation left to JavaScript only

    easy8 min

    The field has no required attribute at all.

  2. 2

    Fix the wrong pattern attribute

    easy8 min

    The attribute is pattern, not regex.

  3. 3

    Fix min used on a text field

    easy8 min

    min only applies to numeric and date inputs.

  4. 4

    Fix the swapped bounds

    easy8 min

    The maximum is smaller than the minimum.

  5. 5

    Fix the wrong length attribute

    easy8 min

    A minimum length uses minlength.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace