Skip to content

Latest commit

 

History

History
72 lines (48 loc) · 2.83 KB

File metadata and controls

72 lines (48 loc) · 2.83 KB

Frontend Mentor - Intro component with sign up form solution

This is a solution to the Intro component with sign up form challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • View the optimal layout for the site depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Receive an error message when the form is submitted if:
    • Any input field is empty. The message for this error should say "[Field Name] cannot be empty"
    • The email address is not formatted correctly (i.e. a correct email address should have this structure: name@host.tld). The message for this error should say "Looks like this is not an email"

Screenshot

Links

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox for layout
  • JavaScript for form validation and dynamic styling
  • Responsive design with mobile-first approach

What I learned

This project helped reinforce my understanding of responsive design and form validation with JavaScript. Here are a few key takeaways:

Regex for Email Validation: I used a regular expression to validate the email format, ensuring it adheres to a typical structure (name@host.tld).

const emailRegex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

Dynamic Error Messages: Error icons and messages were dynamically displayed based on field validation. Each input has associated error states managed through JavaScript functions.

const setError = (index) => {
  formIconError[index].classList.remove("input-icon--hidden");
  formIconError[index].classList.add("input-icon--visible");
  formMessageError[index].classList.remove("span-hidden");
  formMessageError[index].classList.add("span-visible");
};

Focus Management: After form submission, I used .focus() to ensure the user is directed to the first invalid field, enhancing the user experience.

Useful resources