More specific validation

We can think of better validation to the user's fields.

Well, the fields are being validated, but the validation is too lenient. It can be much more robust and focused. We can think of the following rules

  • name - Between two and fifty characters. We can achieve this with @Length(2, 50)

  • email - Must be a valid email. We can use @IsEmail()

  • phone - Must be a valid phone number. We can use @IsPhoneNumber(), and even define a region, like US.

  • password - In a future moment, we'll validate it using @Matches() and a regex for interesting, custom validation. For now, let's leave it as it is.

It can be a great idea to check on the available validators, you may find something interesting.

Last updated