Frontend School

Paytm Profile Update Form with Validation

Machine Coding
easy

Paytm Profile Update Form with Validation

Easy
React
TypeScript
Form Validation
UI

Overview

At Paytm, ensuring data accuracy and a smooth user experience is paramount. For our users to securely manage their accounts and access various services, we often require them to update their profile information. This problem simulates a simplified version of a profile update form, focusing on robust client-side validation to provide immediate feedback to users and prevent invalid data submission.

What you need to do / Task

Your task is to build a React application that renders a "Paytm Profile Update" form. This form should capture user details and implement client-side validation for each field.

  1. Form Fields:
    • Full Name: Text input.
    • Mobile Number: Text input (numeric keyboard preferred).
    • Email Address: Text input (email type preferred).
    • PAN Number (Optional): Text input.
    • Date of Birth: Date input.
  2. Validation Rules:
    • Full Name:
      • Required.
      • Minimum 3 characters, maximum 50 characters.
      • Only alphabets (A-Z, a-z) and spaces are allowed.
    • Mobile Number:
      • Required.
      • Exactly 10 digits.
      • Must start with 6, 7, 8, or 9.
    • Email Address:
      • Required.
      • Must be a valid email format (e.g., user@domain.com).
    • PAN Number (Optional):
      • If provided, must be exactly 10 characters long.
      • Format: AAAAA####A (5 uppercase alphabets, 4 digits, 1 uppercase alphabet).
    • Date of Birth:
      • Required.
      • Must be a valid date.
      • User must be at least 18 years old (calculated from the current date).
  3. Form Submission:
    • On successful submission (all fields valid), display a success message and log the form data to the console.
    • If validation fails, prevent submission and display appropriate error messages for each invalid field.

UI/UX expectations

  • The form should be clearly laid out with labels for each input field.
  • Error messages should appear directly below the respective input fields when validation fails.
  • The "Update Profile" button should be disabled until all required fields are filled and valid.
  • Basic styling is expected for readability and a clean appearance.

Acceptance criteria

  • The form renders correctly with all specified input fields and an "Update Profile" button.
  • Each input field correctly applies its specified validation rules on blur or change events.
  • Error messages are displayed clearly and contextually for invalid inputs.
  • The "Update Profile" button is disabled initially and when any required field is invalid or has validation errors.
  • The "Update Profile" button becomes enabled only when all required fields are filled and valid.
  • Upon successful submission, a success message is displayed, and form data is logged to the console.
  • Upon unsuccessful submission, specific error messages are shown, and submission is prevented.

Constraints

Constraints & assumptions

  • You must use React and TypeScript.
  • All validation logic should be implemented client-side within the React component. Do not use any external form validation libraries (e.g., Formik, React Hook Form).
  • Focus on functional components and React hooks for state management.
  • Assume the current date for age calculation is the date the problem is being solved.

Out of scope

  • Backend integration or API calls for data submission.
  • Extensive, pixel-perfect UI styling; basic readability is sufficient.
  • Complex global state management.
  • Internationalization (i18n).

What interviewers evaluate

  • Correctness and completeness of client-side validation logic for all specified fields.
  • Effective state management for form inputs and validation errors using React hooks.
  • Clear and user-friendly display of validation error messages.
  • Adherence to UI/UX expectations, including button disabled states.
  • Overall code organization, readability, and use of TypeScript.

Loading editor...