Browse DevX
Sign up for e-mail newsletters from DevX


JavaScript Form Validation, the Aspect-Oriented Way : Page 2

Did you know you can apply Aspect-Oriented Programming to client-side JavaScript form validation? Read on to find out how.


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:


The following are just some of the validation methods qForms supports:


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.

Kyle Gabhart serves as the SOA Practice Lead for Web Age Solutions, a provider of technology education and mentoring. Since 2001 he has contributed extensively to the SOA/web services body of knowledge as an author, speaker, consultant, and open source contributor. Find Kyle on the Web at http://www.gabhart.com or reads his blog on SOA at SOAmatters.com.
Thanks for your registration, follow us on our social networks to keep up-to-date