Checking Online Forms with the Validator jQuery Plug-in
If you consider form validation applications to be the kind of coding you least look forward to, keep reading. Thanks to the Validator jQuery plug-in, validating form input from users just got a lot easier. This seven-part series will show you the ways you can use the plug-in to help you build form validation scripts much faster than you may have thought possible.
Checking Online Forms with the Validator jQuery Plug-in - Validating web forms selectively (Page 4 of 4 )
In the previous section, you learned how to perform basic validation on all of the fields of a basic contact form. Nonetheless, as I stated before, the Validator plug-in is flexible enough to check the validity of only specified fields. In other words, it permits you to validate forms selectively.
To demonstrate how this process works, below I created a whole new code sample, which will require only that the first two fields of the form be populated with some values, while the third one will simply be ignored.
The example in question is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Here you have it. Now, by specifying a new "rules" argument within the "validate()" method, it's feasible to indicate which fields will be mandatory. In addition, there's another parameter called "minlength" that will require the obligatory fields to be at least two characters long, in this way refining the selective validation process even more.
With this last hands-on example I'm completing this first tutorial of the series on using the handy Validator jQuery plug-in to check online forms. As usual, feel free to copy and edit all of the code samples developed in this article, so you can acquire a better background in the basic features provided by the plug-in.
Final thoughts
In this first chapter of the series, I introduced you to working with the Validator jQuery plug-in, which makes checking web forms a truly no-brainer process. Nevertheless, I'm only scratching the surface when it comes to exploring all of the helpful features that have been packaged with this plug-in. Therefore, in the forthcoming part, I'll be discussing in more detail the use of the "minlength" argument and a few others that allow you to refine the whole validation process.
Now that you've been properly warned, don't miss the next article!
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.