This is a solution to the Interactive card details form challenge on Frontend Mentor.
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
- Solution URL: Add solution URL here
- Live Site URL: Add live site URL here
- HTML5
- Javascript
- Tailwind CSS
- Mobile-first workflow
Basics of Tailwind CSS
<link rel="stylesheet" href="./tailwind/styles.css">
<label id="error-name" class="text-[12px] tracking-widest text-red-400"></label>
How to use regex
var cardNumber = e.target.value
.replace(/\D/g, "")
.replace(/(\d{4})(\d)/, "$1 $2")
.replace(/(\d{4})(\d)/, "$1 $2")
.replace(/(\d{4})(\d{1,4})/, "$1 $2")
.replace(/( \d{4})\d+?$/, "$1");
- Regex examples - This helped me a lot with the regex mask
- Tailwind Website - Docs
- LinkedIn - Bruno Costa
- Frontend Mentor - @BrnCosta
- Twitter - @_brnCosta