JavaScript Regex Validation — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Regex 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
Accept digits only
easy10 minCheck the value is nothing but digits.
- 2
Reject mixed input
easy10 minCheck a value with a letter is refused.
- 3
Check a fixed format code
easy10 minAccept three capitals followed by three digits.
- 4
Allow an optional prefix
easy10 minAccept the number with or without a leading plus.
- 5
Combine with a range check
medium10 minCheck the shape with a pattern and the range with a number.
Find the bug(5)
- 1
Fix the unanchored digit check
easy8 minWithout anchors a mixed value passes.
- 2
Fix the case-sensitive code check
easy8 minThe code requires capitals, so lowercase must be refused.
- 3
Fix the range checked by pattern
easy8 minA pattern cannot express a numeric range, so check the number.
- 4
Fix the plus treated as a quantifier
easy8 minA literal plus must be escaped.
- 5
Fix the empty value accepted
easy8 minA star allows an empty string, which should be refused.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace