feat: add validation for contact form input fields - #74
Conversation
|
@om-dev007 is attempting to deploy a commit to the Bindupautra Jyotibrat's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @Jyotibrat, |
I'll review the PR and get back to you |
|
@Jyotibrat ok thank you for giving your valuable time |
Jyotibrat
left a comment
There was a problem hiding this comment.
The backend logic works perfectly fine. But, can you add the response to the frontend so that the user knows what is wrong with the message that he/she is typing.
Thank You for your contribution @om-dev007 .
|
Hi @Jyotibrat, |
Raise a separate issue for that and I will assign it to you. Once your frontend PR will be raised then I will check both backend and frontend PR together and merged it if it works. |
|
Hi @Jyotibrat, |
Description
This PR improves server-side validation for the contact form endpoint by validating the submitted input before processing email requests.
Changes Made
Added email format validation using a regular expression.
Added minimum and maximum length validation for the name field.
Added minimum and maximum length validation for the subject field.
Added minimum and maximum length validation for the message field.
Trimmed user input before validation and email processing.
Returns 400 Bad Request with descriptive error messages for invalid input.
Reused validated values when composing the email.
Validation Rules
Field | Validation -- | -- Name | Required, trimmed, 2–50 characters Email | Required, valid email format Subject | Required, trimmed, 5–100 characters Message | Required, trimmed, 10–1000 charactersBenefits
Prevents malformed or invalid submissions.
Improves data quality before sending emails.
Reduces unnecessary email processing.
Provides clearer feedback to users.
Maintains backward compatibility with the existing endpoint.
Testing
✅ Verified valid requests are processed successfully.
✅ Verified invalid email addresses return
400 Bad Request.✅ Verified empty or whitespace-only fields are rejected.
✅ Verified name, subject, and message length constraints.
✅ Confirmed email sending functionality remains unchanged.
Closes #72