Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Ciaran Mckane
Ciaran Mckane
29,438 Points

Form Validation tutorials

Hi guys , just wondering what the best form validation tutorials is ? I've been working on my form for a website and I'm now looking to validate the input using javascript

There are many ways you can do that and "focus & blur" are one of the handy option you can try.

Ciaran Mckane
Ciaran Mckane
29,438 Points

I mean't as far as validating like that the email fields or name,address etc has been entered with correct format data like for required fields

2 Answers

Jason Berteotti
Jason Berteotti
12,352 Points

The easiest way to do this would be with regular expression... to which there does not seem to be a JavaScript tutorial for. There are Java and Ruby tutorials for it, but there would be some obvious discrepancies.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

Benjamin Wegley
seal-mask
.a{fill-rule:evenodd;}techdegree
Benjamin Wegley
Front End Web Development Techdegree Student 18,943 Points

I wanted to piggy back off of Jason's answer and say that Regular Expressions (or regex) are the easiest way to setup some form validation.

Some searching came up with this tutorial. At first regex will look pretty crazy, but once you get the hang of its patterns you find out how powerful it is!

Here is another guide that I found that specifically works with regex and Javascript.

My recommendation would be to gain a basic understanding of regex, they search for a guide specifically on the type of field data you are trying to validate. This will help to narrow regex down and make it less overwhelming, and also help you get the answers you need faster.

Hope this helps!