DEV Community

Cover image for Validate Forms with Event-Driven Javascript
Devon Campbell
Devon Campbell

Posted on • Originally published at raddevon.com on

2

Validate Forms with Event-Driven Javascript

Validating form input on the front-end is a great way to make your users’ experience better. When I’m the user, I’d rather know immediately that something is wrong with my input than having to wait until I submit the form and get the results back.

In my previous video, I showed how you can access a form’s values which is one piece of the front-end form validation puzzle. This video completes the puzzle.

If you want to work along, go to this video's page on my site to get the project starter.

Before I teach you to write Javascript form validation, I’ll teach you ways to validate your form without writing custom JS. HTML5 forms have some validation capability baked right in, and using this is preferable to custom validations.

Later, we move on to a scenario where built-in validation either wouldn’t work or would be more difficult than the custom variety. We’ll start by hooking into an event. This allows us to start running some Javascript when the user interacts with our form. Then, we’ll check the user’s values to see if they are valid. If they aren’t, we’ll stop the form from submitting.

Be sure to leave a comment if you have any questions. Thanks for watching!

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay