dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


advertisement
 

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.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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.



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.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date