Day 2: Building Custom Form Validation with JavaScript


๐ก Introduction:
Today is Day 2 of my coding journey challenge, and I decided to build a user registration form using HTML, CSS, and JavaScript. Instead of using libraries or frameworks, I focused on learning how to do things from scratch โ especially how to validate user inputs and give live feedback on the form.
๐ ๏ธ What I Built:
A simple registration form with the following fields:
Username
Email
Password
Confirm Password
I added logic to:
Prevent form submission if any field is empty
Display error messages near each input
Show green/red borders based on input validity
๐ Key JavaScript Concepts I Practiced:
DOM Selection using
getElementById
Event handling with
form.addEventListener("submit", ...)
Validation logic using custom functions
Dynamically updating the UI with
className
andinnerText
โ Code Snippet Example:
jsCopy codefunction checkRequired(inputArray) {
inputArray.forEach(input => {
if (input.value.trim() === "") {
showError(input, `${formatFieldName(input)} is required`);
} else {
showSuccess(input);
}
});
}
๐ง What I Learned:
Writing clean validation functions helps me reuse logic
Giving visual feedback (like red borders or error messages) makes the form more user-friendly
Working directly with the DOM helps me better understand what JavaScript does behind the scenes
๐๏ธ Daily Reflection:
Even though it seemed simple at first, building this form taught me how much happens under the hood in web development. I'm feeling more confident with each day and excited to keep pushing forward.
๐ Final Words:
If you're also learning JavaScript or starting your web dev journey, I highly recommend building small UI projects like this. Youโll learn a lot more by doing.
Subscribe to my newsletter
Read articles from Godwin Mayodi directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
