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!

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


contact form

What is the best way to validate your contact form? Please help

3 Answers

James Barnett
James Barnett
39,199 Points

It depends on what sorts of fields you want to validate, in general you can:

  • Mix HTML5 input patterns with a JQuery fallback
  • Combine that with server-side PHP
  • Add in a healthy dose of regex
  • Stir and served chilled.

See also: http://html5pattern.com/

Alex Hedley
Alex Hedley
16,378 Points

As James says make sure you validate server sde, this is a must since JS can be turned off in the browser so you can't rely on that alone.

I've used the following jquery plugin which is good http://bassistance.de/jquery-plugins/jquery-plugin-validation/

HTML5 has brought some great new features, cool keyboard changes on smartphones etc

Randy Hoyt
Randy Hoyt
Treehouse Guest Teacher

Hey Israel,

James has it right. We have some content online in the latest projects that discuss this. Andrew talks about jQuery validation here:

I talk about creating the form and doing basic server-side validation in PHP here ...

... and then how to handle some more advanced server-side validation and send the email here ...