Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Card details form using flexbox

@Tobshub

Desktop design screenshot for the Interactive card details form coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Can anyone give me tips on styling the validation error messages and failed validation states? I tried to do some research on it but I couldn't do it. Also please take a look at my validation methods in html and js and let me know if there are better ways of doing thing. Thanks!

Community feedback

Denis 1,060

@Mod8124

Posted

Hi Good Job!

Well, an easy way to check for validations is to create a regex, a match the value of the input with the regex this is going to return true or false so if true is valid otherwise it's invalid. Also, you add style to your validations(inputs) it's better that your inputs have a class over an id that let you do add style to the input easier because CSS has specificity

For example

Css

 .validation {
  background:red;
}
//if the input doesn't have a class (if the input has an id that id has priority) 

.validation.card-holder-name-front {
 background:red;
}
//if the input has class = validation class + input class

JavaScript

   const CardNum_input = const holderNameInput = document.querySelector('.card-holder-name-front');
const CARDREGEX = ^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$

if (  !cardNum_input.value.match(CARDREGEX) ) {
    cardNum_input.classList.add('validation');
} else {
   cardNum_input.classList.remove('validation');
}

By the way, you can look for regex in google like regex for validation card number :)

Marked as helpful

1

@Tobshub

Posted

@Mod8124 Hi! Thanks for the feedback. I suspected JS was the best option for this, so thanks for the clear explanation!

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord