Design comparison
Solution retrospective
I found the solution to disable the default validation message, but i do not understand it at all. (I learned about functions and know about event listeners but i cannot read and understand this one) I'm not sure either that this is the best solution.
Any other feedback is welcomed!
Community feedback
- @half-ctoPosted almost 2 years ago
Hi DRUEVISUAL! Good job on solving layout for this challenge!
regarding JS validation - you could solve this with 2 if statements, one that checks for empty input and other that compares input string with regex here is my take
const email = document.getElementById('email-input'); const submit = document.body.getElementsByClassName('button')[0]; const errorMsg = document.body.getElementsByClassName('error-msg')[0]; const emailRegEx = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; let validateEmail = () => { let inputEmail = email.value; // clear previous error message errorMsg.innerHTML = ''; errorMsg.style.color = '#FB3E3E' //validation if (inputEmail === '') { errorMsg.innerHTML = 'Oops! Please add your email'; }else if (!emailRegEx.test(inputEmail)){ errorMsg.innerHTML = 'Oops! Please check your email'; } else { errorMsg.style.color = '#54E6AF' errorMsg.innerHTML = 'Thank You!'; } } submit.onclick = validateEmail;
1@DRUEVISUALPosted almost 2 years ago@half-cto Thank you! But i couldnt make it work. I will definitely get back to this after learning more about JS!
0
Please log in to post a comment
Log in with GitHubJoin 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