Skip to content

Arnthorny/interactive-card-details-form

Repository files navigation

Frontend Mentor - Interactive card details form solution

This is a solution to the Interactive card details 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:

  • Fill in the form and see the card details update in real-time
  • Receive error messages when the form is submitted if:
    • Any input field is empty
    • The card number, expiry date, or CVC fields are in the wrong format
  • View the optimal layout depending on their device's screen size
  • See hover, active, and focus states for interactive elements on the page

Screenshot

Links

  • Live Site URL: here

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • Vanilla JS - Plain Javascript
  • Icons - For Icons

What I learned

This project added a tad more to my basic knowledge on JS regex syntax. Also learnt more ways to use the String.split method

input {
  /* For curved border gradients*/
  border: solid 1px transparent;
  border-radius: 10px;
  background-image: linear-gradient(white, white), linear-gradient(var(--light-gray-violet), var(--light-gray-violet));

  background-origin: border-box;
  background-clip: padding-box, border-box;
}

/* This background-image can then be changed on focus */

This Javascript code snippet creates an object for the String.split method, and this object allows the method to split strings in fours. It was used in the project to automatically add spaces in the card number input.

const splitByNum = {
  [Symbol.split](str) {
    let num = 4;
    let pos = 0;

    const result = [];
    while (pos < str.length) {
      const groupMatch = str.slice(pos, pos + num);
      if (pos + num >= str.length) {
        result.push(groupMatch);
        break;
      }
      result.push(groupMatch);
      pos += num;
    }
    return result;
  },
};

Useful resources

  • Github Gist - This Github gist code snippet helped manipulate the CSS, to allow border radius be applied to borders with border images.
  • MDN - This MDN Documentation enabled me to create a custom Symbol.split object that allowed the card number input to be separated in fours.

Author

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published