HTML 5 provides some new ways of validating user intput, which could save you a lot of time writing javascript code. This guide demonstrates how to do several standard validation checks using only HTML.
Presence check
A presence check is the simplest check to do. Adding the required attribute to a form element will stop the form from submitting until the element has been filled in.
<input type="text" required />
Format check
There are several ways to do a format check. HTML 5 provides some new input types that combined with the required attribute can be used to validate what the user inputs; the new input types are shown below.
<input type="email" required />
<input type="url" required />
<input type="date" required />
<input type="time" required />
<input type="datetime" required />
<input type="datetime-local" required />
<input type="month" required />
<input type="week" required />
But what if there isn't a type for what you want to validate? There's a new pattern attribute that lets you validate using regular expressions. For example the code below could be used to validate country codes (US, UK, AU, etc).
<input type="text" required pattern="[A-Za-z]{2,3}" />
There's a lot more info on using and creating regular expressions at Regular-Expressions.info