The BEST way to do form validation in JavaScript

preview_player
Показать описание
A lot of JavaScript form validation tutorials won't show you how to write code that can be reused for multiple forms.

00:00 Intro
01:47 Creating the form
22:34 Validating the form

In this #JavaScript tutorial, we'll see how to create a set of functions which can be used to validate a form using the HTML validation attributes that, by default, the browser uses to trigger its own validation.

We'll start off by creating an #HTML form from scratch and we'll use Tailwind and FontAwesome to add some styling and icons.

Once we've got a form set up, we'll see how to use the HTML validation attributes to trigger the default browser validation. Once we've seen how this works, we'll create JavaScript to override this behaviour and replace it with our own validation logic which matches what the browser already provides. By doing this, we can customise the look and feel of the validation the user sees on each input field. Channel Handle @codebubb
Рекомендации по теме
Комментарии
Автор

Do you ever create your own form validation in JavaScript now? Or are you using some package/library with your React/Angular/Vue projects?

codewithbubb
Автор

I came here for the validation but I am so glad that I watched you put that form together as well. Great stuff.

celfabri-nh
Автор

Youtube need more stuff like that, every channel has the same extra-beginner stuff, thank you 🙏🙏⭐⭐

astroboy
Автор

This is such a great video, and so easy to understand.
So glad i found it, it really helped clear some questions i had about form validation.
Thank you

okolipeace
Автор

Good to see you were on my YouTube Home Page today - 27.05.2022 08:07

MonotonyTV
Автор

Really nice video thanks for sharing, wish I had seen it before. We need more stuff like this which is for advance levels. Good job

nehakannaujia
Автор

Thanks Bubb for this video, which goes way further in code structuration then most I have seen on this topic. I just wonder why you chose to add the icon elements in the HTML instead of creating / removing them in the JS script. Would you proceed that way in real life or is it only for the video purposes?

Christy-Bee
Автор

Great thinking and logic implementation. A masterclass

mabillama
Автор

Thank you for the great video, should this work for 'select' tags as well?

falanlaguerre
Автор

Really nice video, very different from other validation vids out there. I have a question. What's the difference between your method and using checkValidity() method from JS api?

relja_
Автор

I really want to understand how the minLength attribute property had more precedence over the required attribute property

ryanwalter
Автор

If you use event.preventDefault() in your validation function, you need to manually submit the form if it is valid.
Am I right?
For example,
if(valid) { formElement.submit() }

inteltone
Автор

hey! idk why i'm not getting the errors and no texts appear.. idk why is that, but can you give me the source-code so i can see what im doing wrong.. ?

_rin.
Автор

Hi, where can I find the code of your tutorial, because I don't wanna spend time on html/css part.. Thank you!

anitaabdurrahmani
Автор

Hello. A great code for validation. I've tried doing it on my own form and it worked fine when the form was placed in the html code, but when I rewrote the code and loaded the form dynamically the validation no longer worked. Getting error here: formElement.setAttribute('novalidate', ' ' ); Uncaught TypeError: Cannot read properties of null (reading 'setAttribute') at validateForm (main.js:376:17)
i.e. now only the html validation works.
What can I do to make the javaScript validation work instead?? 🙂

marie
Автор

Thank you for good lesson. But I encountered problem. Submit doesn't work (page doesn't reload after filling form and pressing submit button. Please could you help me with this issue! Thank you in advdnce!

romanryabchinskiy
Автор

Hi, Thanks for the tutorial!
I'm wondering if someone edit our html with the inspect element? it will work?
Thanks again!

takisnani
Автор

After the first validationOptions for the required attribute my form only display error for only the first input field. Does anybody else have the same issue?

zuekiin
Автор

Great video but it there is a problem. The error message will not go away until I have clicked the submit button twice and then it will go away. Does anyone know why this is?

jaylonnichols
Автор

Would you post the code for this tutorial? :)

lukas.szarkowski