Checking Numbers and File Extensions with jQuery`s Validator Plug-in
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.
Checking Numbers and File Extensions with jQuery`s Validator Plug-in - Review: the digits and dates options (Page 2 of 4 )
In case you haven’t read the previous article of the series, where I explained how to work with the “digits” and “date” options of the plug-in, below I reintroduced the pertinent examples. Here they are:
(example on using the ‘digits’ option)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<p>Date of Birth <input type="text" name="birth" class="required" /></p>
<p><input type="submit" value="Submit" /></p>
</form>
</body>
</html>
As you can see above, it’s extremely simple to check if a value entered in a given form field contains only digits by utilizing the “digits” options, as illustrated by the first code sample. On the other hand, the last case shows how to work with the “date” argument to check for well-formatted dates. That’s not rocket science, is it?
So far, so good. At this stage, you’re hopefully familiar with using the previous options provided by the Validator plug-in for validating numbers and dates respectively. Nonetheless, as I stated in the beginning, the plug-in offers a couple of additional arguments that allow you to directly check numbers and file extensions. Of course, if you’re planning to build a web site that will let users to upload files to the web server, this last option might be especially helpful as long as it is backed up with strong server-side validation.
In the next section I’m going to develop another example that will teach you how to validate numbers with ease.
To see how this example will be built, click on the link below and keep reading.