This is a message.

Minimal setup for validator

Here we have a form that has valid HTML5 syntax. We have used email, url and number inputs as well as a normal text input with a pattern attribute. The requred attribute is used to indicate a mandatory field. The old school but handy maxlength attribute makes it impossible to enter more than 30 characters.

Sample registration form

Enter bad values and then press the submit button.

standalone demo

HTML coding

<form id="myform">
<h3>Sample registration form</h3>
<p> Enter bad values and then press the submit button. </p>
<label>email *</label>
<input type="email" name="email" required="required" />
<label>website *</label>
<input type="url" name="url" required="required" />
<label>name *</label>
<input type="text" name="name" pattern="[a-zA-Z ]{5,}" maxlength="30" />
<input type="number" name="age" size="4" min="5" max="50" />
<p id="terms">
<label>I accept the terms</label>
<input type="checkbox" required="required" />
<button type="submit">Submit form</button>
<button type="reset">Reset</button>


JavaScript coding

This is the simple part. Simply initialize validator and you'll get all the HTML5 niceties.



You need to place the script block after the HTML code or you can alternatively use jQuery's $(document).ready to execute the script as soon as the webpage's Document Object Model (DOM) has been loaded. Read more about that from the User's Manual.

CSS coding

We have used one external stylesheet for the design. It has styling for the whole form. Here we focus on the validation and the error message:

/* error message */
.error {
/* supply height to ensure consistent positioning for every browser */
border:1px solid #E1E16D;
padding:3px 10px;

/* CSS3 spicing for mozilla and webkit */
-moz-box-shadow:0 0 6px #ddd;
-webkit-box-shadow:0 0 6px #ddd;