Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Challenge: Implement a Validation Flow | Validation Flows and Safe Execution Patterns
Practice
Projects
Quizzes & Challenges
Quizzen
Challenges
/
PHP Error Handling and Exceptions
Sectie 3. Hoofdstuk 2
single

single

bookChallenge: Implement a Validation Flow

Veeg om het menu te tonen

Taak

Swipe to start coding

Create a validation function for a user registration form that checks the username, email, and password fields. If a field is invalid, the function must throw a ValidationException with a relevant message.

  • If username is empty, throw a ValidationException with the message "Username cannot be empty".
  • If email is not a valid email address, throw a ValidationException with the message "Invalid email address".
  • If password is less than 8 characters long, throw a ValidationException with the message "Password must be at least 8 characters long".
  • If all fields are valid, return the string "Registration successful".

Oplossing

Taak

Swipe to start coding

Create a validation function for a user registration form that checks the username, email, and password fields. If a field is invalid, the function must throw a ValidationException with a relevant message.

  • If username is empty, throw a ValidationException with the message "Username cannot be empty".
  • If email is not a valid email address, throw a ValidationException with the message "Invalid email address".
  • If password is less than 8 characters long, throw a ValidationException with the message "Password must be at least 8 characters long".
  • If all fields are valid, return the string "Registration successful".

Oplossing

Create a validation function for a user registration form that checks the username, email, and password fields. If a field is invalid, the function must throw a ValidationException with a relevant message.

  • If username is empty, throw a ValidationException with the message Username cannot be empty;
  • If email is not a valid email address, throw a ValidationException with the message Invalid email address;
  • If password is less than 8 characters long, throw a ValidationException with the message Password must be at least 8 characters long;
  • If all fields are valid, return the string Registration successful.

Unit Test Checklist

  • Throws a ValidationException with the correct message if username is empty;
  • Throws a ValidationException with the correct message if email is not a valid email address;
  • Throws a ValidationException with the correct message if password is less than 8 characters long;
  • Returns "Registration successful" if all fields are valid.
Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 3. Hoofdstuk 2
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

some-alt