Design comparison
Solution retrospective
Hello ! I'm starting to learn JS
I'm in truble with the email check... I've done i think the if empty functions but i don't now how to verify the email , the good format.
Anyone may help ? :)
Community feedback
- @MelvinAguilarPosted 12 months ago
Hello there ๐. Good job on completing the challenge !
I have some suggestions about your code that might interest you.
-
Verifying an email address in JavaScript typically involves using regular expressions or built-in functions to check if the email follows a valid format. Here's a basic example
function isValidEmail(email) { const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; return emailRegex.test(email); } // Example usage const emailToVerify = "[email protected]"; if (isValidEmail(emailToVerify)) { console.log("Email is valid!"); } else { console.error("Email is invalid"); }
- It seems that the current implementation has validations to display error messages, but there is no mechanism to remove or clear those error messages. Ideally, if a user modifies the input to correct the error, the error message should be removed.
- Directly manipulating styles in JavaScript can lead to code that is hard to maintain. Create a CSS class with the desired styles and use JavaScript to add or remove that class.
- Consider organizing your code more efficiently by moving all the document.querySelector calls outside of the event listener and assigning them to variables at the beginning.
- Additionally, if you've already obtained the element in
const firstName
, there's no need to usedocument.querySelector('.first-name')
again. You can simply use the variablefirstName
for subsequent operations.
I hope you find it useful! ๐
Happy coding!
Marked as helpful0@JulienLachPosted 12 months ago@MelvinAguilar Hello, big thanks for you reply. I will try your suggestions ! I didn't know about your last bullet point, calling variables. I will fix my code
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