JavaScript Form Validation

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 17. 06. 2019
  • Form validation is one of the most common web development tasks. There are many ways to do form validation, but JavaScript is one of the best and easiest ways to write form validation. In this video I will be covering all of the concepts of form validation in JavaScript as well as how to display helpful error messages to the user. By the end of this video you will have all the tools you need to implement form validation in your own projects.
    📚 Materials/References:
    HTML Forms Explained: ‱ Learn HTML Forms In 25...
    CodePen Code: codepen.io/WebDevSimplified/p...
    🧠 Concepts Covered:
    - Preventing form submission in JavaScript
    - Using HTML attributes to validate input elements
    - Displaying form validation messages to the user
    - How to check for form errors
    🌎 Find Me Here:
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    #FormValidation #WDS #JavaScript

Komentáƙe • 370

  • @rkeenan85
    @rkeenan85 Pƙed 3 lety +109

    Thank you for making these so short. I just need a basic idea of how this works. I have not done validation in awhile, and I was so stuck at work. This saved my life. I will definitely have to pick up your courses. You have saved me twice now.

    • @WebDevSimplified
      @WebDevSimplified  Pƙed 3 lety +17

      I'm glad I have been able to help!

    • @hamzailyas7617
      @hamzailyas7617 Pƙed 2 lety

      @@WebDevSimplified make videos short like that one 👍
      It will help you and also great for us

    • @el-jivacarter552
      @el-jivacarter552 Pƙed rokem

      can u do one for email and password

    • @krakatoom
      @krakatoom Pƙed rokem

      @@WebDevSimplified thanx for the clip. but my brwoser doesnt get back the error message. cant say why. and as for the use of name in js it say something about depracated. can u help me out!

  • @pappucdl
    @pappucdl Pƙed 4 lety +18

    What I greatly like about your video is, they are concise and to the point. Also you solve problem in a single video which is excellent. Keep up the "Awesome Work!!!"

  • @cineymatic
    @cineymatic Pƙed 3 lety +2

    Almost 15 videos and landed here only to realize how perfect this video was. Just on point.

  • @westfield90
    @westfield90 Pƙed 5 lety +29

    I’m so glad I found your channel. You explain it so well

    • @WebDevSimplified
      @WebDevSimplified  Pƙed 5 lety +8

      Thank you! I'm glad you understand my teaching style.

  • @nickpapadopoulos7466
    @nickpapadopoulos7466 Pƙed 3 lety +13

    Turns out all I needed was "required", but this was far more valuable than I anticipated. I can find many uses where you prevent the form from being submitted in the future. This video is dense in information, on point explanations without any second wasted. Thank you!

  • @rayanjlidi2220
    @rayanjlidi2220 Pƙed 3 lety +21

    He wasn't kidding when he said he's going to simplify the web for us. Thank you soo much

  • @TertiusRoach
    @TertiusRoach Pƙed 4 lety

    Just want to extend my thanks, straight to the point, proper mic and camera. Subbed :)

  • @rogerrock12games
    @rogerrock12games Pƙed 2 lety +3

    I appreciate these courses. I tried your way and it didn't work, but at this point with all the learning I've begun to absorb, I was able to make a better validator using regular expressions, which while I'm having a really hard time with them, are very fun and useful if you know how to apply those concepts!

  • @destrayo3049
    @destrayo3049 Pƙed 2 lety

    I like that you do not waste time you get straight into it .
    good luck.

  • @matiashillmann1278
    @matiashillmann1278 Pƙed 4 lety +3

    This is great, I learned a lot. Thank you!!

  • @gibsgibus
    @gibsgibus Pƙed 5 lety +4

    awesome dude ! thank you ! love the logic you used.

  • @BACKSPACECADET
    @BACKSPACECADET Pƙed 4 lety

    Love how simple you made this

  • @awaisn
    @awaisn Pƙed 4 lety

    GOOD VIDEO. Short and to the point. Thanks for this!

  • @lefamofokeng8291
    @lefamofokeng8291 Pƙed rokem

    I actually have always been intimidated by JS part of creating sites but you make that appear so fun . Thanks!😊

  • @eftiprwtopapadakis9310
    @eftiprwtopapadakis9310 Pƙed 3 lety

    finally a simple and easy to understand javascript validation form!

  • @bagel389
    @bagel389 Pƙed 3 lety

    thank you, I've been trying to do this for a bit.

  • @joshkoster2851
    @joshkoster2851 Pƙed 3 lety +1

    Thanks so much mate, you make it so simple! You got my sub.

  • @webstyle876
    @webstyle876 Pƙed 4 lety +1

    ĐžŃ‚Đ»ĐžŃ‡ĐœĐ°Ń ĐżĐŸĐŽĐ°Ń‡Đ° ĐžĐœŃ„ĐŸŃ€ĐŒĐ°Ń†ĐžĐž , быстрыĐč Ń‚Đ”ĐŒĐż - Ń€Đ°ĐŽŃƒĐ”Ń‚)

  • @simonekranawetter316
    @simonekranawetter316 Pƙed 2 lety +3

    Thank you for these videos. It's really simple to follow along, you have a clear way of explaining concepts and every time I try to implement them myself I have an easier time remembering because you explain it in a very easy to understand way and don't waste any time. Thank you so much for sharing!

  • @timurfayziyev1647
    @timurfayziyev1647 Pƙed 3 lety

    Juda kotta yordam berdingiz raxmat! :)from Uzbekistan

  • @patrick-dev
    @patrick-dev Pƙed 4 lety

    The way you explain the code while you're coding it is AMAZING! Thanks

  • @joashemmanuel288
    @joashemmanuel288 Pƙed 3 lety

    Thank you for the video. It was concise and understandable to a beginner.

  • @wahabrehman6848
    @wahabrehman6848 Pƙed 4 lety

    Probably one of the best tutorials I've seen on CZcams. Too bad the algorithm doesn't recommend you enough

  • @vaidehikawal4117
    @vaidehikawal4117 Pƙed 3 lety +11

    Simplicity level is on high N' The way you say "Oops"😍 got me theređŸ€ŸđŸ’Ż

    • @sunsetsleeper
      @sunsetsleeper Pƙed 3 lety

      This mad tough i can't even find the open to live server

  • @AndrewKwabula
    @AndrewKwabula Pƙed 4 lety +1

    Dude, you are a great teacher, you negate questions from your students because your explanations are so clear.

  • @timowiedmer2991
    @timowiedmer2991 Pƙed 3 lety

    Cool! It actually works even without defining the consts in the beginning ;)

  • @mykolamysko987
    @mykolamysko987 Pƙed 5 lety +111

    I must say you'll get in a same league with NetNinja and BradTraversy in no time if you keep it up. Awesome content.

    • @WebDevSimplified
      @WebDevSimplified  Pƙed 5 lety +21

      Thank you! That is a huge compliment. I think both those teachers are amazing.

    • @pastorfred2543
      @pastorfred2543 Pƙed 5 lety +3

      I discovered him not long ago and he's really amazing I must confess.. I followed his tutorials concerning async await and I was able to apply it in my current inventory project..

    • @jackfrost8969
      @jackfrost8969 Pƙed 3 lety +2

      he is far better than BradTraversy and just as good as NetNinja if not even better.

    • @gon_9062
      @gon_9062 Pƙed 3 lety

      @@pastorfred2543 Ù€ŰŽ

    • @susmitislam1910
      @susmitislam1910 Pƙed 3 lety

      You saw quite far into the future my friend

  • @thetech3624
    @thetech3624 Pƙed 3 lety

    Amazing, Amazing, Amazing. Couldn't have explained it better. Keep it up.

  • @slmshady539
    @slmshady539 Pƙed 4 lety +7

    this was actually asked during an interview for an internship.

  • @ajayshankhwar730
    @ajayshankhwar730 Pƙed 4 lety

    your channel shares some really good content ....what i was looking for

  • @hiwayshoes
    @hiwayshoes Pƙed 5 lety +5

    Hi there! You make these concepts so understandable. I appreciate your channel so much. Please keep making these great videos... Cheers!

  • @uttampaul2467
    @uttampaul2467 Pƙed 4 lety

    Awesome,you explain so easily...Thank you very much.

  • @makelovenotwar9941
    @makelovenotwar9941 Pƙed 3 lety

    Will experiment other validations with your codes here as my guide. Thanks!

  • @diddlenfiddle7311
    @diddlenfiddle7311 Pƙed 5 lety +2

    Only 5k views? I hope you get more man, good stuff!

    • @WebDevSimplified
      @WebDevSimplified  Pƙed 5 lety

      Thank you! 5k is more than a lot of my videos so I am very happy with that.

  • @jayamali1422
    @jayamali1422 Pƙed rokem

    Thank you this video helped me a lot .

  • @devoided2
    @devoided2 Pƙed 4 lety +1

    omg this vid saved me
    thank you very much!

  • @joakimwretlind4016
    @joakimwretlind4016 Pƙed 5 lety

    Short with good explanation. Very nice.

  • @xxrartoxx
    @xxrartoxx Pƙed 4 lety

    That was really helpful, great video

  • @geraldakabike2026
    @geraldakabike2026 Pƙed 5 lety +2

    Learnt Something New Today... Much Appreciated

  • @mohamedelyeszormati
    @mohamedelyeszormati Pƙed rokem

    This was a helpful tutorial, thank you.

  • @majidamini237
    @majidamini237 Pƙed 3 lety

    thanks a lot it was better than a calculator project because i understood every thinh in this video :))

  • @TheMaro57
    @TheMaro57 Pƙed rokem +8

    A note for beginners. The code runs by order so that things to work smoothly. Do not mix up the order of the If commands. Also take out the action figure inside the because that is for only when the html file is hosted on a different server.

    • @01suku77
      @01suku77 Pƙed rokem +1

      holy shit thanks

    • @m.j.mcintear793
      @m.j.mcintear793 Pƙed rokem

      how to call the function with each of these variables as an argument emailaddress variable and emailconfirm variables
      Do you know how to make two of the same emails need to match and is that client side validation or server side? Inquiry of js on html form

    • @TheMaro57
      @TheMaro57 Pƙed rokem +1

      @@m.j.mcintear793 I forgot all that I learned sorry lol

    • @dracophobic3381
      @dracophobic3381 Pƙed rokem

      @@m.j.mcintear793 I would assume you could do something like this in js:
      If(email1 !== email2){
      Error.value.push("emails must match")
      }

  • @nurainnabila2218
    @nurainnabila2218 Pƙed 2 lety

    Thank you so much !!! Love this channel !!!!

  • @splitlang
    @splitlang Pƙed 5 lety

    Hi thank you I can not get away from the channel but because of work thanks

  • @vaishnavimithapalli9071
    @vaishnavimithapalli9071 Pƙed 3 lety +1

    i saw this video 2 times coz 1st i was just staring at him coz he is ssoooooooooo handsome and 2nd time..........dude you literally made it simple to understand. Thankyou soo soo much!!!!

  • @degsewtegegne
    @degsewtegegne Pƙed rokem

    Thank you very much! Short
    And it's easy.👍

  • @qwertykeypad789
    @qwertykeypad789 Pƙed 5 lety

    Once again...
    Great video!!!

  • @tkchamp5120
    @tkchamp5120 Pƙed 3 lety +1

    this guy misspells things the exact same way as me, i feel at home

  • @dur1m4r93
    @dur1m4r93 Pƙed 3 lety

    very helpful video, thanks a lot, good job!

  • @Hirand2349_3
    @Hirand2349_3 Pƙed 3 lety

    Simply Superb ... Kept cmplx things easier

  • @shadon_official2510
    @shadon_official2510 Pƙed 2 lety

    such an amazing and concise video

  • @consoledoterror971
    @consoledoterror971 Pƙed 4 lety +9

    All I wanted in a single video.

  • @hrushikeshpatil3772
    @hrushikeshpatil3772 Pƙed 3 lety

    Straight to the point.....

  • @deboragetachew5677
    @deboragetachew5677 Pƙed 3 lety

    Very helpful. Thank you.

  • @manueltylan827
    @manueltylan827 Pƙed 2 lety

    Simple and clearđŸ”„đŸ”„đŸ”„đŸ”„đŸ”„đŸ”„đŸ”„

  • @beganarasusekar6195
    @beganarasusekar6195 Pƙed 3 lety +1

    You are incredible man😍

  • @NNNedlog
    @NNNedlog Pƙed 3 lety

    Thanks a lot for this tutorial

  • @nashsmith2303
    @nashsmith2303 Pƙed 3 lety

    Nice and simple! love it. Do you have experience with making web accessible form validation? Would love to see a slightly more in depth version focusing on form validation compliant with WCAG

  • @steveotieno8441
    @steveotieno8441 Pƙed 2 lety +5

    My Guy, The Way you structured that Code, You're smart!!!

  • @diogostein848
    @diogostein848 Pƙed rokem

    This helped me a lot. I was adding an event listener to the submit button, not the form. So the validation wasn't working. Thanks for the tutorial.

  • @__jake.m
    @__jake.m Pƙed 2 lety

    Thank you so much man!

  • @mr.anything6882
    @mr.anything6882 Pƙed 3 lety

    SO COOL!!!!I LEARNED A LOT

  • @andrei-petrulazar5564
    @andrei-petrulazar5564 Pƙed 2 lety

    Awesome! Thank you!!

  • @htmlcssjavascriptjqueryphp5855

    thanks a lot really helped me !

  • @imjaystationbest2
    @imjaystationbest2 Pƙed 3 lety

    Bro thank you so much im working on a website and all the other ones are indian language thanks for speaking English.

  • @DaraMojibayo
    @DaraMojibayo Pƙed 3 lety

    Awesome video, good content and nice explanations. Do you have a JavaScript series video

  • @davi_singh
    @davi_singh Pƙed 4 lety +1

    Awesome video, would be good to go through some of the HTML5 validation that comes built into most browsers

  • @jalen.austin
    @jalen.austin Pƙed 4 lety +1

    Thanks for this

  • @TheMaster201989
    @TheMaster201989 Pƙed 8 měsĂ­ci

    nice work and great simply explained it

  • @oliveroshea5765
    @oliveroshea5765 Pƙed rokem

    Awesome, many thanks

  • @darccau7204
    @darccau7204 Pƙed 3 lety

    thanks, it help me a lot

  • @carlandres3319
    @carlandres3319 Pƙed 4 lety

    Thanks for using vanilla JavaScript !!

    • @WebDevSimplified
      @WebDevSimplified  Pƙed 4 lety +1

      You're welcome! I generally use vanilla JS in all my tutorials when possible. I only reach for a library if it really saves me time.

  • @OutMagic
    @OutMagic Pƙed rokem

    So helpful man, thank you C:

  • @muhammedshafeeralip4178
    @muhammedshafeeralip4178 Pƙed 2 lety

    Thank you ,You Saved me...

  • @arjun-de6dr
    @arjun-de6dr Pƙed 3 lety

    Awesome explanation

  • @eclecticann
    @eclecticann Pƙed 3 lety

    hiya! thanks for this post. very helpful. question though. what happens when they fill out all the input fields? would u recommend an else statement? thanks.

  • @motorazr777
    @motorazr777 Pƙed 5 lety

    Hi buddy , all your videos are amazing, thanxs so much for doing this type of content.
    Would you mind if you might do a video about best practices of coding? Things as, which resources to study, and a Top languages to learn as a beginner. Thanxs a lot again !!!

    • @WebDevSimplified
      @WebDevSimplified  Pƙed 5 lety +1

      Thanks. I try to point out best practices in all of my project based videos when I come across them. I also have a few videos on how to study and best resources. They are in the top 10 and discussion playlists on my channel.

    • @motorazr777
      @motorazr777 Pƙed 5 lety

      @@WebDevSimplified Great, well, I'll check out your channel to watch that video. Thanks again .

  • @isulakshani12
    @isulakshani12 Pƙed 2 lety

    Really important video

  • @lgiardili
    @lgiardili Pƙed rokem

    good job!! thanks!!

  • @trinityshelly3965
    @trinityshelly3965 Pƙed 2 lety

    super helpful video thanks

  • @Carlos-td6bz
    @Carlos-td6bz Pƙed 4 lety

    dude, you are the fucking GOAT explaining this shit, keep it uppppppppppppp

  • @rishengopaldass1103
    @rishengopaldass1103 Pƙed 4 lety +1

    Hi there.
    Thank you for the video. Was great!
    Although I noticed that validating input types wasn't included. For example. What if the user entered a number in the Name field.
    Please can you help with 'Validation Types', across fields, so to speak. It would be a useful extension to this video.
    I've been trying for so long but cannot get it right. This may help others as well.
    Most grateful!

  • @OhOk616
    @OhOk616 Pƙed rokem

    Thanks for the help

  • @hesamalavi9
    @hesamalavi9 Pƙed 4 lety

    Hi, thanks very much for the video. What if you have more fields, like last name and you would like the message to come up if that field is empty too. I know I could add the required to the HTML but I was interested in getting the message using js

  • @integrateeverythingpower
    @integrateeverythingpower Pƙed 3 lety +1

    Please make a video on form validation both on keyup and after clicking submit on one video pls

    • @ConsulthinkProgrammer
      @ConsulthinkProgrammer Pƙed 3 lety

      There are several alternatives for making form application. For an example we could use Appsheet, but Appsheet has a limit of only 10 accounts for the free version. For another alternatives, we could use google apps script for more flexible customization and so we could add pretty good functions such as geolocation, upload files or qrcode and barcode scanner too. One of the references about login form with slider animation is czcams.com/video/zbH-6r2QjP4/video.html

  • @TomasMisura
    @TomasMisura Pƙed 3 lety

    this quite useful as I am trying to do ajax call using form submit event but it constantly refreshes. I know what's happening but could not avoid it. Now I get it.

  • @enricoisola3955
    @enricoisola3955 Pƙed 3 lety

    FANTASTIC!

  • @denmarkcube6027
    @denmarkcube6027 Pƙed rokem

    This is what I'm looking for. Thank you !

  • @TeeTV1
    @TeeTV1 Pƙed 4 lety

    Thank you for your quick and easily understandable content. I'd like to know how I would check the validation of an email address. For example, if they accidentally forget the '@'. How would I go about that?

    • @Kitulous
      @Kitulous Pƙed 3 lety

      ik it's late for you but for others:
      if (!email.value.match(/.*?@.*?\.*/)) {
      messages.push("Enter the correct format for the e-mail");
      }
      It's a very, very, very basic e-mail regex, you can look up more complex and more specific ones online.

  • @michelecicozzi1197
    @michelecicozzi1197 Pƙed 4 lety

    Nice content.I just have a question... but if you sanitize user inputs on client side ( for example to prevent sql injections or something similar ), is this easier to bypass using something like Burpsuite, I mean use of valid input, intercept and then inject sql injection code using burp..??

  • @robertefremov9380
    @robertefremov9380 Pƙed 3 lety +1

    i couldn't quite get if it wipes the content in the "messages" array after the function has run, or when you run the function again it wipes the previous error messages? Or is it the event being over that wipes the content in the "messages" array?

  • @zettabytesofknowledge8235

    Oh wow you make this look so easy and I'm learning this at light speed now, thank you! So I'm getting stuck w my js not linking:
    "Add a paragraph after the closing form tag with a statement letting the user know the form has been reset.
    Apply an id to with the appropriate value that matches the appropriate JavaScript statement.
    "
    I think that means add a event listener to the reset button, if so, how? please or can I add multiple functions to a reset button? Like popup alert that its been reset and a hidden message made visible that form has been reset? IDK why in real life id need to add such redundancy, just that is what I'm interpreting the assignment says needs to happen.
    what I have so far, please keep in mind its my first js assignment and its erroring out:
    4 10 'unhideThankYou' is defined but never used.
    7 12 'hideThankYou' is defined but never used.
    16 12 'myFunction' is defined but never used.
    "document.getElementById("lastmodified").innerHTML = document.lastModified;
    function unhideThankYou() {
    document.getElementById("thankyou").style.visibility = "visible";
    }
    function hideThankYou() {
    document.getElementById("thankyou").style.visibility = "hidden";
    }
    function myFunction() {
    document.getElementById("notshown").innerHTML = "Thank you for submitting the form";
    }
    function myFunction() {
    // Adds the text to the heading tag.
    document.getElementById("h2").innerHTML="The form has been turned in. Thank you!";
    document.getElementById("submitbutton3").innerHTML="Thank you the form has been submitted";
    }
    "
    ""On the reset button, add the onclick attribute with a function name of your choosing for your reset message as the value.
    On the submit button, add the onclick attribute with a function name of your choosing for the form submission message as the value."

  • @BhavinTrivedi-of4zs
    @BhavinTrivedi-of4zs Pƙed 2 lety

    Thank you so much đŸ„°

  • @olamideolajuyi2311
    @olamideolajuyi2311 Pƙed 2 lety +1

    Easy to understand

  • @nickwoodward819
    @nickwoodward819 Pƙed 2 lety

    Great vid. Out of interest, if you've validation server side too I assume you don't bother returning the errors to the client then? Just rely on the fact that the front end validation is the same as the back end?

  • @suyogamin1859
    @suyogamin1859 Pƙed 4 lety +1

    nice explanation bro

  • @paulpancake
    @paulpancake Pƙed rokem

    Thank you for the tutorial. But how do I enable the default again, after giving a false password once and the correcting it? It keeps showing the error message :(

  • @pushpakgupta7396
    @pushpakgupta7396 Pƙed 5 lety +36

    simplicity:100

  • @beerendratravellingfiles
    @beerendratravellingfiles Pƙed 4 lety

    Hello brother pls Help me
    How can we add admit card download features or certificate verification features pls help
    Me..

  • @921dgratias
    @921dgratias Pƙed 3 lety

    Question, when using .join(',') method. If you click on the submit button multiple times the same error message will also appear multiple times since they are being pushed in the array. what's the way around it?