Checking Numbers and File Extensions with jQuery`s Validator Plug-in
(Page 1 of 4 )
In this sixth part of a seven-part series on the jQuery framework's Validator plug-in, I discuss the use of the “number” and “accept” options. They allow you to validate both numeric data and file extensions in online forms with remarkable ease.
As you might have heard, the popular jQuery JavaScript library has a growing number of plug-ins that contribute to extending its functionality. Among these numerous pluggable components, there’s one that lets you perform powerful client-side validation on web forms with remarkable ease and without having to deal with complex JavaScript APIs at all.
I'm talking about the Validator plug-in, a solid piece of software written by Jörn Zaefferer that allows you to check data collected through HTML forms in all sorts of smart ways, ranging from validating empty strings, numbers and dates, to verifying email addresses and well-formatted URLs.
Thus, if you’re interested in learning how to put this useful validation library to work for you, then read this series of articles. In it you’ll find an approachable guide that will show you how to take advantage of the most useful features that come with the Validator plug-in.
Having outlined the main goal of this group of tutorials, it’s time to refresh the topics that were covered in the last article. It explained how to use the “digits” and “date” options provided by the plug-in to check for numeric values and well-formatted dates. Actually, checking to see if data entered in a web form satisfy these conditions is only a matter of calling the already familiar “validate()” method of the plug-in with one of the arguments mentioned above. It’s that easy, really.
But if all of these neat validation capabilities aren’t good enough for you, let me tell you that the Validator library still has a few other handy options that permit you to check numbers and file extensions in a straightforward fashion. Obviously, this last one is particularly useful when performing file uploads via HTTP, so in this sixth chapter of the series I’m going to demonstrate how to use it in concrete cases, in addition to explaining how to validate simple numbers.
Therefore, it’s time to continue exploring the neat data checking abilities of the Validator plug-in. Let’s do it right now!
Next: Review: the digits and dates options >>
More JavaScript Articles
More By Alejandro Gervasio