Demo  Download
Source (.as)December 02 2005 10:22:39
Example (.fla)December 02 2005 10:22:39 (.as)December 02 2005 10:22:39
Source and example (.zip)December 02 2005 10:22:39 (Required for publish)
Fill in the fields and mouseover "Validate" to validate.

  • 17.8.2004 - Added a new datatype, boolean, see below for comments. Mainly exists because like to be consistent and I'm lazy too. No example exists.
  • 22.4.2004 - FormValidator is now initialized into the _global scope. I hadn't realized this feature was missing.
  • 21.4.2004 - Fixed one more bug related to how "real" numbers were handled (incorrectly).
  • 20.4.2004 - Fixed a few bugs. Also changed the way variables are handled in other than the 'self'-scenario. Should work a whole lot better now.
  • 23.9.2003 - Added resetForm()-method. Now I only need to find a good way to make the inputs reflect it too...
  • 26.5.2003 - Found a bug in my String-addons. Download the new if you use a prior one.
  • Enum-type field (I suppose regexp would do this too but...)
  • Regexp-type field
  • More examples (var-handling, complex cases etc.)
  • Docs
  • Smarter error reporting. (Report what is going wrong)

This list exists only to refresh my memory. There is no ETA for these changes. Most changes happen when the need for more feature emerge.

Header from source
// FormValidator 0.3.8 - Simple form validation for flash
// Author  : Niklas Lindgren 
// You are free to use this in any way you choose. If you redistribute this
// text should be included. I am not to be considered liable to any grief  
// or information loss (or hair loss for that matter :) due to using this.
// 0.3.8 - Fixed an error in the email-regexp
// 0.3.7 - Fixed an error in the email-regexp
// 0.3.6 - Minor fix to date-checking
// 0.3.5 - Added boolean (_FIELD_BOOL). Quite unnecessary really, I only added it
//         so FV won't get stuck on them. I do like to add them to the form-array
//         so I can use the copyValuesTo()-method.
// 0.3.4 - I finally realized what _global does. FormValidator is now
//         initialized into the _global scope.
// 0.3.3 - Fixed one more bug. Now "real" numbers are also copied correctly
// 0.3.2 - Some bugfixes. Path to variables works like it should now when you
//         don't use "self". "Real" numbers were validated incorrectly.
// 0.3.0 - Added resetForm() -method for resetting form to default values.
//         Now if I only could figure out a way to get the inputs to reflect it too...
// 0.2.8 - _Keep It Simple Stupid_. When I changed the code to how it should 
//         have been in the first place (it was suddenly obvious), I achieved 
//         a slight increase in speed.
// 0.2.7 - Further optimization attempted but with quite poor success. But,
//         on the bright side, I now have an extended String-object :)
// 0.2.6 - Tried to optimize the code a bit because it became *slow*.
//         Quite a bit was changed... It seems that Objects that contain
//         Objects is not a good idea. Further optimization is still needed.
//         The way your form is structured also effects the runtime. My demo
//         is a horrible scenario. It's very expensive because of multiple 
//         compilations of complex regexps are required. A real world 
//         application would not need that.
// 0.2.5 - Fixed the DateConstruct bug/feature. Decided loose-checking is
//         not really what this is about.
// 0.2.4 - Even more bugfixes. New demo flash.
// 0.2.3 - More DateConstruct bugfixes. And a new bug/feature introduced :D
//         Invalid data or empty data in an optional DateConstruct evals to
//         to true as the constructed date is then built to empty (= "") so
//         data-integrity is still ok.
// 0.2.2 - Bugfix regarding DateConstruct
// 0.2.1 - Fixed a bug in the date check
//         added a feature; four digit years are now checked to be in a 
//         certain yearspan (predefined century-span, default 1700-2199)
// 0.2   - Added two datatypes. Date and DateConstruct
// 0.1.5 - Fixed a bug in email checking
// 0.1.4 - Added copyValuesTo() function
// 0.1.3 - Enabled variables to be stored in the FormValidator-object
// 0.1.2 - Fixed a bug in email checking
// 0.1   - Initial Release
//   - An email address with an ip-address as host will not validate to true
//   - Dates aren't formally verified to be valid. Only "grammatically"
//   - Proper instructions for use.
// Initiation
//   objname = new FormValidator() or 
//   objname = new FormValidator(varHolder, formElements)
// varHolder is an object where the variables are stored. 
//   This is just my way of doing this. I suppose it wouldn't be a big effort 
//   to modify the code to use textfield-instancenames instead to reference 
//   them directly. But this would work only for textfields...
//   Since version 0.2.6 assigning varHolder the value "self" will make
//   the FormValidator object store the variables in an object called 
//   '_FV_vars' which resides on the timeline, Not in the FormValidator-object 
//   itself. The textfield variable would be '_FV_vars.varname'. The downside 
//   to this is textfields aren't updated before a frameadvance (=default 
//   values don't show up).
// formElements is the form passed to the object as an array 
//   in which each form-element is an array in the form:
//   [variable name][default value][type][required]
// Forms can be redefined at a later point by calling 
// objname.defineForm(varHolder, formElements)
//   FormValidator.prototype._FIELD_TEXT  for textfields
//   FormValidator.prototype._FIELD_NUM   for numeric fields
//   FormValidator.prototype._FIELD_EMAIL for e-mail addresses
//   FormValidator.prototype._FIELD_DATE  for dates in the format
//   FormValidator.prototype._FIELD_DATEC for date constructs. See example.
//   FormValidator.prototype._FIELD_BOOL  for booleans. (Checkboxes)
// After init all you have to do is call objname.validateForm() which
// returns true or false
//  - (downloadable from
//    (A huge thanks to Pavils Jurjans for making regexps for flash!)
//  - (included)
// METHODS (not all but those of value to you, aka public methods :)
// o validateForm()
//   Validates the form-values
//   returns true or false
// o isFormOk()
//   The result from the previous validation can be fetched by calling
//   objname.isFormOk()
//   returns true or false
// o copyValuesTo(target)
//   Copies the form-values to an object target. (I used this to propagate
//   a LoadVars-object). This might be unnecessary since you could define
//   the target as varHolder.
//   returns nothing
// o defineForm(varHolder, formElements)
//   Defines or re-defines the form (meta)-data
// o resetForm()
//   Resets all the variables to their default values