JavaScript Form Validation

  Рет қаралды 901,711

Web Dev Simplified

Web Dev Simplified

Күн бұрын

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/Web...
🧠 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/Web...
CodePen: codepen.io/Web...
#FormValidation #WDS #JavaScript

Пікірлер: 368
@rkeenan85
@rkeenan85 3 жыл бұрын
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 3 жыл бұрын
I'm glad I have been able to help!
@hamzailyas7617
@hamzailyas7617 2 жыл бұрын
@@WebDevSimplified make videos short like that one 👍 It will help you and also great for us
@el-jivacarter552
@el-jivacarter552 Жыл бұрын
can u do one for email and password
@krakatoom
@krakatoom Жыл бұрын
@@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!
@jalen.austin
@jalen.austin 5 жыл бұрын
Thanks for this
@Victor_Marius
@Victor_Marius 3 жыл бұрын
Do you really need type=button for a button element? I think it submits the form even with just Submit or, a more correct way,
@saikumardasari4220
@saikumardasari4220 Жыл бұрын
how we can use feildset with legend tag in react with one example
@sherryvlogs2009
@sherryvlogs2009 2 жыл бұрын
u look like Homelander from THE BOYS
@TR1XT3RZ360
@TR1XT3RZ360 3 жыл бұрын
Followed this step by and step and its not working!!
@pappucdl
@pappucdl 4 жыл бұрын
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!!!"
@mykolamysko987
@mykolamysko987 5 жыл бұрын
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 5 жыл бұрын
Thank you! That is a huge compliment. I think both those teachers are amazing.
@pastorfred2543
@pastorfred2543 5 жыл бұрын
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 3 жыл бұрын
he is far better than BradTraversy and just as good as NetNinja if not even better.
@gon_9062
@gon_9062 3 жыл бұрын
@@pastorfred2543 ٤ش
@susmitislam1910
@susmitislam1910 3 жыл бұрын
You saw quite far into the future my friend
@westfield90
@westfield90 5 жыл бұрын
I’m so glad I found your channel. You explain it so well
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thank you! I'm glad you understand my teaching style.
@vaidehikawal4117
@vaidehikawal4117 4 жыл бұрын
Simplicity level is on high N' The way you say "Oops"😍 got me there🤟💯
@sunsetsleeper
@sunsetsleeper 3 жыл бұрын
This mad tough i can't even find the open to live server
@rayanjlidi2220
@rayanjlidi2220 3 жыл бұрын
He wasn't kidding when he said he's going to simplify the web for us. Thank you soo much
@bluwhale9004
@bluwhale9004 3 жыл бұрын
XD
@pushpakgupta7396
@pushpakgupta7396 5 жыл бұрын
simplicity:100
@leodragonheart754
@leodragonheart754 4 жыл бұрын
dude, it doesnt work... I have no idea why... I dont get any text saying name required.
@slmshady539
@slmshady539 4 жыл бұрын
this was actually asked during an interview for an internship.
@integrateeverything
@integrateeverything 3 жыл бұрын
Please make a video on form validation both on keyup and after clicking submit on one video pls
@ConsulthinkProgrammer
@ConsulthinkProgrammer 3 жыл бұрын
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 kzbin.info/www/bejne/sJOrXmmoZ7adhpY
@robertefremov9380
@robertefremov9380 3 жыл бұрын
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?
@calumbarratt2174
@calumbarratt2174 3 жыл бұрын
Anyone else not able to get this to work following this exactly..?
@nickpapadopoulos7466
@nickpapadopoulos7466 3 жыл бұрын
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!
@erichernandez8379
@erichernandez8379 4 жыл бұрын
I followed instructions exactly and the browser won't show an error message
@ita755khushalkoli2
@ita755khushalkoli2 2 жыл бұрын
same happens with me
@joshk9571
@joshk9571 2 жыл бұрын
i think that happens because
@krakatoom
@krakatoom Жыл бұрын
@ITA755 Khushal Koli same same
@AXUMV
@AXUMV Жыл бұрын
@@joshk9571 yesh, it's because
@coltonaallen
@coltonaallen Жыл бұрын
@@AXUMV you see, the reason for this bug is
@pulga961
@pulga961 4 жыл бұрын
mdn docs tell us to not relay on html form validation because it can be avoided somehow....on the other hand your javascript implementation is not accessible at all...we should programaticaly move focus to error element or give it attribute role="alert" or smth like that....
@hanesmitter1469
@hanesmitter1469 4 жыл бұрын
Javascript validation on browser is still avoidable. The best is backend validation [completely out of touch ]
@steveotieno8441
@steveotieno8441 3 жыл бұрын
My Guy, The Way you structured that Code, You're smart!!!
@samarmohan9891
@samarmohan9891 4 жыл бұрын
When I used var instead of const, it didn't work. Keep that in mind if you are reading this
@consoledoterror971
@consoledoterror971 4 жыл бұрын
All I wanted in a single video.
@GamingIsFunHUN
@GamingIsFunHUN 2 жыл бұрын
The exact copy of this code doesn't work wtf.
@ReyBanYAHUAH
@ReyBanYAHUAH 2 жыл бұрын
Always remember we must repent of our sins (sin is transgression The Law Of Yahuah The Father in Heaven. The Law are The Books: Genesis, Exodus, Leviticus, Numbers, & Deuteronomy). We must repent of our sins and Have Belief On Yahusha The Messiah. HE Died and Rose three days later so that we can be forgiven of our sins! Come to HIM🙂🙂🙂🙂🙂🙂🙂🙂
@haritechsolutions5365
@haritechsolutions5365 3 жыл бұрын
How to edit read only web page in Google chrome without getting manipulate error while submitting
@luisgustavo.5449
@luisgustavo.5449 Жыл бұрын
Nice video! But guys, please DON'T LIMIT THE PASSOWRD CHARACTERS to just 20 chars, othewise the hackers would be so grateful to you...
@user13rs258
@user13rs258 Жыл бұрын
So this validation we are applying through Javascript is known as server side validation? Or just front-end validation?? Because in the html it's doesn't shows up so it shouldn't be front-end validation right it must be server side? 😅😅😅 And if we did validation in the back-end that will also be known as Server side validation right??? Please help me clear my doubt.. Thanks!
@coding_with_mayavi0
@coding_with_mayavi0 Жыл бұрын
Bro iam used for prevent form but is showing uncaught typeError :cannot read properties of undifned(reading'addEventListner') At (line) what happent
@subliminakeys1674
@subliminakeys1674 2 жыл бұрын
Okay I've watched tons of your videos... How do you copy and paste so fast? You are definitely not using the keyboard. It seems like you are just dbl clicking or something...
@victorsvensson7914
@victorsvensson7914 Жыл бұрын
The more than and less than conerning the amount of charcters can be done in html. You do not need Javascript for that. If someone does not have Javascript enabled, then your validation will fail. That is not good WCAG practice. 😛
@vaishnavimithapalli9071
@vaishnavimithapalli9071 3 жыл бұрын
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!!!!
@pawansubedi8544
@pawansubedi8544 Жыл бұрын
if(name.value ==null) i have does this excluding (names.value====" ") but it doesnot work..whats the problem any solution
@dunialebowski8320
@dunialebowski8320 Жыл бұрын
hello, is anyone having issues when typing name.value in their editor? I'm using Visual Studio code and whenever I write this, it has a strikethrough and this explanation "The declaration was marked as deprecated here."
@paulpancake
@paulpancake Жыл бұрын
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 :(
@drekforder2952
@drekforder2952 2 жыл бұрын
ReferenceError: Cannot acces 'error' before initialization what do I do with that? It's refreshing the page uven if I put the button blocking outside of if function
@ssenkoomianthony6006
@ssenkoomianthony6006 Жыл бұрын
hello i appreciate your timely assistance please how can set information by default while devolving a website? coz i am stuck from some where.
@xxapoloxx
@xxapoloxx 10 ай бұрын
How do you addapt Forms to work well with SPAs and Ajax? they seem like legacy code from the 90s
@alexauga
@alexauga 2 жыл бұрын
I replicated this in VS Code and when I click Submit it takes me to my C:/ drive directory, not sure what I'm doing wrong?
@y.l.deepak5107
@y.l.deepak5107 2 жыл бұрын
hello sir im learning u r stuff in channel from quite while sir i would like to ask i have a project on lab maintenance system using php and mysql idk how to do about that project sir i hope u could u pls help me sir
@jushwanth.g.v8298
@jushwanth.g.v8298 2 жыл бұрын
whn i click on submit nothing happens when i checked the debugger it says ReferenceError: document is not defined.
@MUHAMMADZEESHAN-tp7zy
@MUHAMMADZEESHAN-tp7zy 3 жыл бұрын
what the fuck... if u already use "required" in input field then u don't need to implement javascript code.
@swastikjainsj
@swastikjainsj 2 жыл бұрын
aree i want real time Message eg like i am typing number but the input forn validation is from Alphabets it to show live
@johnatteo822
@johnatteo822 2 жыл бұрын
Bro you didn't even teach us the best part?? How to set the username and passwords and how to go to the next page after submitting...
@RockiBY
@RockiBY 3 жыл бұрын
How can I check for a already existing (phone number/ nickname/ email) when filling in a field with?
@gibsgibus
@gibsgibus 5 жыл бұрын
awesome dude ! thank you ! love the logic you used.
@timtech9361
@timtech9361 2 жыл бұрын
This is a basic form validation for 3 year olds. What if there are multiple fields to fill out (more than 5). This method is not efficient then.
@aaryanbhurtel8577
@aaryanbhurtel8577 3 жыл бұрын
can you make a video how to make a blog with free domain and hosting and ya website should be from js please...
@kirinkappa5662
@kirinkappa5662 4 жыл бұрын
.tutorial { simplicity: 100%; usefulness: 100%; viewer-time-investment: none; } youtuber.subscribers++;
@ojomudamola6674
@ojomudamola6674 Жыл бұрын
But if I want the input.value to show the after being successful? . Pls I really need this
@m.j.mcintear793
@m.j.mcintear793 Жыл бұрын
how to call the function with each of these variables as an argument emailaddress variable and emailconfirm variables
@palmwaytech
@palmwaytech Жыл бұрын
On a website , im trying to get some form of a contact form for clients to use , they enter some simple information and it goes to a web hosting place , i log in and see the messages or it can go to my gmail. Any ideas?
@olamideolajuyi2311
@olamideolajuyi2311 2 жыл бұрын
Easy to understand
@xilongzhang6856
@xilongzhang6856 2 жыл бұрын
The code does not work for me. then I downloaded the code from your codepen but it’s not working as well :(
@jstdarwn
@jstdarwn 2 жыл бұрын
u didn't even use else statement.... hows that? can anyone please explain what kind of assignment is this?
@juniorpirela6885
@juniorpirela6885 3 жыл бұрын
Is secure do this validations only with javascript?? anyone can inject malicious code I think
@sherryvlogs2009
@sherryvlogs2009 2 жыл бұрын
He wasn't kidding when he said he's going to simplify the web for us. Thank you soo much
@MultiMunja
@MultiMunja 2 жыл бұрын
You are great. You make sshort videos and I love them. Just speak little bit slower because most of us is learning and if Your video is one minute longer it would be better :D. But that is just my opinion. But You are still great
@alphaomegaalines5935
@alphaomegaalines5935 3 жыл бұрын
this video is outdated, when i press submit i see my entire directory tree at 4:29 at the same time, i cannot find the github repository for this video
@foxjonesofficial
@foxjonesofficial 3 жыл бұрын
Only 4k likes? 😢
@RockyKev
@RockyKev 5 жыл бұрын
using the -- the required part is only front-end validation. You should also do back-end validation. For proof - visit a form with a "required" attribute, visit devtools, edit HTML, and remove "required". If you can still submit it, then the site didn't do proper back-end validation and you can break their site.
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
That is true. This tutorial is only focused on frontend validation, though. I have other tutorials on Node.js/Express validation.
@tkchamp5120
@tkchamp5120 3 жыл бұрын
this guy misspells things the exact same way as me, i feel at home
@luzbritez7547
@luzbritez7547 5 жыл бұрын
i can't belive how attractive you are, thanks for the video btw it helped me
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thanks. I'm really glad you enjoyed the video and found it helpful.
@brunosgaming9574
@brunosgaming9574 2 жыл бұрын
bro the thumbnail is out of this video, i needed the correct video thats shown in thumbnail :(
@5Pectral
@5Pectral 5 жыл бұрын
This is a very slick and simple tutorial. However I would be weary of claiming to "cover all concepts" of validation as you only used one of the many input types HTML provides. Also, you began by creating an event listener to prevent its default behavior but then continued to use it to validate input and push error messages. Ideally these should be their own functions, but I get that you may have consolidated them for the sake of the tutorial. It's just that your viewers are going to pick up the habits they see, and unless you say otherwise they might start writing doEverything() functions :P Allinall this tutorial definitely hit the mark, and whats more, they'll only get better!
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thank you for the feedback. I can definitely see the desire for a separate function that builds the error messages which is called from the event listener to clean up the code. I feel for this example though since it was so small it probably isn't worth it especially since it can add extra complexity to the tutorial.
@MR2U2B
@MR2U2B 3 жыл бұрын
Thou lackest one point: checking availability of a username.
@gravitashebynimus3425
@gravitashebynimus3425 Жыл бұрын
the .innerText for some reason dosn't work for me, it's not included in the dropdown selection when doing erroeElement.innerText = messages.join(', ');
@diddlenfiddle7311
@diddlenfiddle7311 5 жыл бұрын
Only 5k views? I hope you get more man, good stuff!
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
Thank you! 5k is more than a lot of my videos so I am very happy with that.
@worldoflanguages1043
@worldoflanguages1043 2 жыл бұрын
what is the difference between null and "" in input, why did you use 2 conditions not one?
@aya2222
@aya2222 3 жыл бұрын
He reminds me of the main character guy from the movie Social network.
@Rygoken
@Rygoken 2 жыл бұрын
Loved the vid but for some reason, my validations are not going through.
@dnjosh10
@dnjosh10 Жыл бұрын
Your explanation was very okay and understanding but you speak too fast
@17Kalash
@17Kalash 5 ай бұрын
I don't get the use of defer inside the script where we connect the js in the head of the html
@cineymatic
@cineymatic 3 жыл бұрын
Almost 15 videos and landed here only to realize how perfect this video was. Just on point.
@pheapsochetra1357
@pheapsochetra1357 4 жыл бұрын
can you show me how to create password and confirm password in form validation ??
@DavisTibbz
@DavisTibbz 3 жыл бұрын
Let “cpassword” be confirm password field variable If(password.value === cpassword.value) { //display your error. }
@BGWFILMSTUDIOS
@BGWFILMSTUDIOS 4 жыл бұрын
once you hit the submit button where does it go and can you show how it's done .
@EnglishBasicsGrammars
@EnglishBasicsGrammars 2 жыл бұрын
I want to learn js from basics to advance... please share sm pdf..
@None-0n3
@None-0n3 2 жыл бұрын
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!
@imjaystationbest2
@imjaystationbest2 3 жыл бұрын
Bro thank you so much im working on a website and all the other ones are indian language thanks for speaking English.
@rishengopaldass1103
@rishengopaldass1103 4 жыл бұрын
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!
@WeeboPlatform
@WeeboPlatform 3 жыл бұрын
How to get an alert message for incorrect username or password?
@victorsvensson7914
@victorsvensson7914 Жыл бұрын
Why are you not using
@TheMaro57
@TheMaro57 Жыл бұрын
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 Жыл бұрын
holy shit thanks
@m.j.mcintear793
@m.j.mcintear793 Жыл бұрын
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 Жыл бұрын
@@m.j.mcintear793 I forgot all that I learned sorry lol
@dracophobic3381
@dracophobic3381 Жыл бұрын
@@m.j.mcintear793 I would assume you could do something like this in js: If(email1 !== email2){ Error.value.push("emails must match") }
@nbvdib2098
@nbvdib2098 4 жыл бұрын
very good but you speak too fast ahah sry im French
@matiashillmann1278
@matiashillmann1278 4 жыл бұрын
This is great, I learned a lot. Thank you!!
@chiranjeevimeti8969
@chiranjeevimeti8969 4 жыл бұрын
WHY R U NOT ZOOMING THE SCREEN WHILE CODING
@geraldakabike2026
@geraldakabike2026 5 жыл бұрын
Learnt Something New Today... Much Appreciated
@WebDevSimplified
@WebDevSimplified 5 жыл бұрын
I'm really glad I could help
@mi5956
@mi5956 5 жыл бұрын
learned
@digihz_data
@digihz_data 2 жыл бұрын
Nice,but....please speak a bit slower. Getting stressed hearing you rush things.
@SRG-Learn-Code
@SRG-Learn-Code 2 жыл бұрын
You can change playback speed or rewind, also I recommend to enable closed captions.
@samannoyb
@samannoyb Жыл бұрын
Yeah, but "required" is also an option!
@TheMaster201989
@TheMaster201989 10 ай бұрын
nice work and great simply explained it
@dailymeow3283
@dailymeow3283 3 жыл бұрын
Is there a way i can sanitize the input against XSS, to check each name.value character if equals to something like \>|\
@ocean.w.a.v.e.s
@ocean.w.a.v.e.s Жыл бұрын
hey do you have a contact form submit video??
@arcanepersona1676
@arcanepersona1676 2 жыл бұрын
Hi Kyle, i rewatched the video a couple of times but i couldn't get pass one issue which is my error message doesn't disappear even after i wrote the input correctly, i get all error messages stacked on my sign up window ..
@LJ-tb4om
@LJ-tb4om 8 ай бұрын
how do I validate/require a number, uppercase, and lowercase letter? It doesn't seem to follow the same format as the length requirements.
@ShubhAgarwal__
@ShubhAgarwal__ 3 жыл бұрын
Hey i am having the following error. Plz Help Me Uncaught ReferenceError: messages is not defined at Test7.html:20
@messironaldo1708
@messironaldo1708 2 жыл бұрын
Can someone explain to me what the (e) is for @3:14?
@TomasMisura
@TomasMisura 3 жыл бұрын
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.
@sumanroshan2873
@sumanroshan2873 2 жыл бұрын
you look like taylor lautner in the movie twilight
@randy4443
@randy4443 3 жыл бұрын
preventdefault doesn't work with post
@shahulya7654
@shahulya7654 3 жыл бұрын
/ gives me all the files in my computer when I click on the button🤷🏻‍♀️
@ameyjangam2485
@ameyjangam2485 2 жыл бұрын
Hey, were you able to solve the issue?
JavaScript Client-side Form Validation
29:07
Florin Pop
Рет қаралды 715 М.
Learn JavaScript Event Listeners In 18 Minutes
18:03
Web Dev Simplified
Рет қаралды 588 М.
Will A Guitar Boat Hold My Weight?
00:20
MrBeast
Рет қаралды 256 МЛН
Как подписать? 😂 #shorts
00:10
Денис Кукояка
Рет қаралды 8 МЛН
Inside Out 2: ENVY & DISGUST STOLE JOY's DRINKS!!
00:32
AnythingAlexia
Рет қаралды 12 МЛН
Do you choose Inside Out 2 or The Amazing World of Gumball? 🤔
00:19
Form validation using Javascript on the client side for beginners
9:35
JavaScript Academy
Рет қаралды 396 М.
Node.js Doesn’t Suck Anymore
16:59
Web Dev Simplified
Рет қаралды 113 М.
The BEST way to do form validation in JavaScript
59:45
Code With Bubb
Рет қаралды 19 М.
JavaScript Promises In 10 Minutes
11:31
Web Dev Simplified
Рет қаралды 1,7 МЛН
Learn HTML forms in 8 minutes 📝
8:39
Bro Code
Рет қаралды 348 М.
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
Form Validation Project | HTML, CSS and Javascript | Logic First Tamil
29:53
Learn JavaScript DOM Traversal In 15 Minutes
14:44
Web Dev Simplified
Рет қаралды 225 М.
Improve your form validation hints without JS!
12:46
Kevin Powell
Рет қаралды 66 М.
Will A Guitar Boat Hold My Weight?
00:20
MrBeast
Рет қаралды 256 МЛН