Design comparison
Solution retrospective
I really learned a lot from this project. I was able to do alot of research of how client side validation of user input on a form is being done. This helped me in understanding the importance of regular espression in validating the correspondance of an input that should fir a particular pattern.
Being a to maniputlate the default behavior of a form and making it easy for users to know the errors they are making in filling the for is really satisfying.
This project has also thought me how to navigate through different pages using JavaScript window.location method.
What challenges did you encounter, and how did you overcome them?I encountered some challenges styling the listed icons I used but I was able to get it done after settling down to think about it well.
also I faced challenges with the JavaScript code, displaying the email from the client side was not something I know before now, but I was able to discover the window.localStorage.setItem() method that helped save the input value and I was then able to display on the success page with another method window.localStorage.getItem().
What specific areas of your project would you like help with?On this project, honestly it was not easy at all so I wouldn't know where I need to make adjustments, but to the best of knowledge I did it well.
Community feedback
- @MahmoodHashemPosted 4 months ago
Hello there
Congratulations on successfully finishing the challenge!
Your project is absolutely amazing.
Here are a few suggestions that can further enhance your project:
HTML comes with a built-in form validation API that is widely supported by modern browsers. This API allows you to perform client-side form validation without the need to write complex regular expressions. Instead, you can leverage the HTML's built-in validation attributes and properties to handle form validation.
The key steps to implement form validation using the HTML validation API and JavaScript are as follows:
Add Validation Attributes to the Form and Input Fields :
- Add the
noValidate
attribute to the<form>
element to disable the browser's default form validation behavior. - Add the
required
attribute to the input fields that should be mandatory. - Specify the appropriate
type
attribute for the input fields (e.g.,type="email"
for email fields) to enable built-in validation for the specific input type.
<form action="" noValidate> <input type="email" required id="email" placeholder="[email protected]" /> </form>
Handle Form Submission with JavaScript :
- Add an event listener to the
submit
event of the form. - Inside the event listener, call the
preventDefault()
method to prevent the default form submission behavior. - Check the validity of the form fields using the
validity
property, which provides various sub-properties likevalueMissing
andtypeMismatch
. - Based on the validity state, you can display appropriate error messages or perform other actions.
const form = document.querySelector('form'); const email = document.getElementById('email');form.addEventListener('submit', (e) => { e.preventDefault(); if (email.validity.valueMissing) { // Display "Please fill out this field" error } else if (email.validity.typeMismatch) { // Display "Please enter a valid email address" error } else { // Form is valid, proceed with submission } });
Hope you found that helpful
Keep up the hard work
0 - Add the
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