single
Challenge: Implement a Validation Flow
Swipe um das Menü anzuzeigen
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
usernameis empty, throw aValidationExceptionwith the message "Username cannot be empty". - If
emailis not a valid email address, throw aValidationExceptionwith the message "Invalid email address". - If
passwordis less than 8 characters long, throw aValidationExceptionwith the message "Password must be at least 8 characters long". - If all fields are valid, return the string "Registration successful".
Lösung
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
usernameis empty, throw aValidationExceptionwith the message "Username cannot be empty". - If
emailis not a valid email address, throw aValidationExceptionwith the message "Invalid email address". - If
passwordis less than 8 characters long, throw aValidationExceptionwith the message "Password must be at least 8 characters long". - If all fields are valid, return the string "Registration successful".
Lösung
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
usernameis empty, throw a ValidationException with the messageUsername cannot be empty; - If
emailis not a valid email address, throw a ValidationException with the messageInvalid email address; - If
passwordis less than 8 characters long, throw a ValidationException with the messagePassword must be at least 8 characters long; - If all fields are valid, return the string
Registration successful.
Unit Test Checklist
- Throws a
ValidationExceptionwith the correct message ifusernameis empty; - Throws a
ValidationExceptionwith the correct message ifemailis not a valid email address; - Throws a
ValidationExceptionwith the correct message ifpasswordis less than 8 characters long; - Returns "Registration successful" if all fields are valid.
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen