O'Reilly logo

Mastering jQuery by Alex Libby

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a simple validation plugin

Until now, our examples have been based around individual fields, such as an e-mail address or a website URL. The code is heavily duplicated, which makes for a bloated and inefficient solution.

Instead, let's completely flip our approach and turn our code into a generic plugin. We'll use the same core process to validate our code, depending on the regex that has been set within the plugin.

For this next exercise, we'll use a plugin produced by Cedric Ruiz. Although it is a few years old, it illustrates how we can create a single core validation process that uses a number of filters to verify the content entered in our form. Let's make a start by performing the following steps:

  1. From the code download that accompanies ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required