More Form Validation
Requiring certain fields to have a value is a good starting point, but often applications demand more sophisticated validation capabilities. QForms rises to this challenge.
Out-of-the-Box Validation Methods
A variety of field validation methods come pre-built with qForms. To use these methods, simply reference the form and the form field name, and then call the method:
myForm.fieldName.validateXXX()
The following are just some of the validation methods qForms supports:
validateAlpha()
validateAlphaNumeric()
validateCreditCard()
validateDate()
validateEmail()
validateInteger()
validateLength()
validatePassword()
validatePhoneNumber()
validateSSN()
validateState()
validateZipCode()
Each of these methods also has an isXXX() version that returns a Boolean value and can be used in customized validation routines (described below).
Additional validation methods include the following:
createDependencyTo() The designated field is required only if the source field is selected/completed.
isNotNull()/isNotEmpty() Evaluate null and empty cases regardless of the field type (text, check/radio group, selection, and etc.).
validateAtLeastOne() List n number of fields, requiring at least one of them to be selected/completed.
Custom Validation Routines
Beyond its stock validation routines, qForms offers a rather extensive capability to define custom validation routines. This extensibility centers around two key methods:
validateExp() evaluates the supplied Boolean expression to determine a field's validity, such as verifying that a particular field is equal to a certain value, or ensuring that a field contains a certain number of characters
_addValidator() facilitates the creation of a fully customizable JS function that serves as a new Validator (complete with validateXXX() and isXXX() methods)
Time-Saving Form Validation
The qForms API is a simple, flexible JavaScript library that eases the development and maintenance of client-side JavaScript. In particular, qForms is an effective library for defining HTML form validation in a very lightweight, aspect-oriented manner. The next time that you are faced with the need for client-side validation of a Web form, give qForms a try. It just might reduce your development time and testing cycles, while leaving your forms clean and crisp.