Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

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,377 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
STAFF
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 ...