Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Challenge: Implement a Validation Flow | Validation Flows and Safe Execution Patterns
/
PHP Error Handling and Exceptions
Sección 3. Capítulo 2
single

single

bookChallenge: Implement a Validation Flow

Desliza para mostrar el menú

Tarea

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".

Solución

Tarea

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".

Solución

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 desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 2
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

some-alt