Packageorg.apache.flex.validators
Classpublic class PostCodeValidator
InheritancePostCodeValidator Inheritance Validator Inheritance flash.events.EventDispatcher

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

The PostCodeValidator class validates that a String has the correct length and format for a post code.

Postcode formats consists of the letters C, N, A and spaces or hyphens

Country codes one be one or two digits.

For example "NNNN" is a four digit numeric postcode, "CCNNNN" is country code followed by four digits and "AA NNNN" is two letters, followed by a space then followed by four digits.

More than one format can be specified by setting the formats property to an array of format Strings.

The validator can suggest postcode formats for small set of know locales by calling the suggestFormat method.

Postcodes can be further validated by setting the extraValidation property to a user defined method that performs further checking on the postcode digits.

Fullwidth numbers and letters are supported in postcodes by ignoring character width via the flash.globalization.Collator equals method.

MXML SyntaxexpandedHide MXML Syntax

The <mx:PostCodeValidator> tag inherits all of the tag attributes of its superclass, and adds the following tag attributes:

  <mx:PostCodeValidator
    countryCode="CC"
    format="NNNNN"
    formats="['NNNNN', 'NNNNN-NNNN']"
    wrongFromatError="The postcode code must be correctly formatted."
    invalidFormatError="The postcode format string is incorrect."
    invalidCharError="The postcode contains invalid characters."
    wrongLengthError="The postcode is the wrong length."
  />
  

See also

org.apache.flex.formatters.PostCodeFormatter


Public Properties
 PropertyDefined By
  countryCode : String
Optional 1 or 2 letter country code in postcode format
PostCodeValidator
 Inheritedenabled : Boolean
Setting this value to false will stop the validator from performing validation.
Validator
  extraValidation : Function
A user supplied method that performs further validation on a postcode.
PostCodeValidator
  format : String
Valid postcode format that postcodes will be compaired against.
PostCodeValidator
  formats : Array
An array of valid format strings to compare postcodes against.
PostCodeValidator
  incorrectFormatError : String
Error message for an incorrect format string.
PostCodeValidator
  invalidCharError : String
Error message when the post code contains invalid characters.
PostCodeValidator
 Inheritedlistener : Object
Specifies the validation listener.
Validator
 Inheritedproperty : String
A String specifying the name of the property of the source object that contains the value to validate.
Validator
 Inheritedrequired : Boolean
If true, specifies that a missing or empty value causes a validation error.
Validator
 InheritedrequiredFieldError : String
Error message when a value is missing and the required property is true.
Validator
 Inheritedsource : Object
Specifies the object containing the property to validate.
Validator
 Inheritedtrigger : IEventDispatcher
Specifies the component generating the event that triggers the validator.
Validator
 InheritedtriggerEvent : String
Specifies the event that triggers the validation.
Validator
  wrongFormatError : String
Error message for an incorrectly formatted postcode.
PostCodeValidator
  wrongLengthError : String
Error message for an invalid postcode.
PostCodeValidator
Protected Properties
 PropertyDefined By
 InheritedactualListeners : Array
[read-only] Contains an Array of listener objects, if any, or the source object.
Validator
 InheritedactualTrigger : IEventDispatcher
[read-only] Contains the trigger object, if any, or the source object.
Validator
 InheritedresourceManager : IResourceManager
[read-only] A reference to the object which manages all of the application's localized resources.
Validator
 InheritedsubFields : Array
An Array of Strings containing the names for the properties contained in the value Object passed to the validate() method.
Validator
Public Methods
 MethodDefined By
  
Constructor.
PostCodeValidator
  
errorsToLocale(locale:String):Boolean
Sets the error strings to be from a another locale.
PostCodeValidator
 Inherited
initialized(document:Object, id:String):void
Called automatically by the MXML compiler when the Validator is created using an MXML tag.
Validator
  
suggestCountryCode(locale:String = null):String
Sets the suggested country code for for a given locale.
PostCodeValidator
  
suggestFormat(locale:String = null, changeErrors:Boolean = false):Array
Sets the suggested postcode formats for a given locale.
PostCodeValidator
 Inherited
validate(value:Object = null, suppressEvents:Boolean = false):ValidationResultEvent
Performs validation and optionally notifies the listeners of the result.
Validator
 Inherited
validateAll(validators:Array):Array
[static] Invokes all the validators in the validators Array.
Validator
  
validatePostCode(validator:PostCodeValidator, postCode:String, baseField:String):Array
[static] Convenience method for calling a validator.
PostCodeValidator
Protected Methods
 MethodDefined By
 Inherited
Sets up all of the listeners for the valid and invalid events dispatched from the validator.
Validator
  
doValidation(value:Object):Array
[override] Override of the base class doValidation() method to validate a postcode.
PostCodeValidator
 Inherited
Returns the Object to validate.
Validator
 Inherited
Returns a ValidationResultEvent from the Array of error results.
Validator
 Inherited
isRealValue(value:Object):Boolean
Returns true if value is not null.
Validator
 Inherited
Disconnects all of the listeners for the valid and invalid events dispatched from the validator.
Validator
 Inherited
This method is called when a Validator is constructed, and again whenever the ResourceManager dispatches a "change" Event to indicate that the localized resources have changed in some way.
Validator
Events
 Event Summary Defined By
 InheritedDispatched when validation fails.Validator
 InheritedDispatched when validation succeeds.Validator
Public Constants
 ConstantDefined By
  ERROR_INCORRECT_FORMAT : String = incorrectFormat
[static] Value errorCode of a ValidationResult is set to when the format contains unknown format characters.
PostCodeValidator
  ERROR_INVALID_CHAR : String = invalidChar
[static] Value errorCode of a ValidationResult is set to when the postcode contains an invalid charater.
PostCodeValidator
  ERROR_WRONG_FORMAT : String = wrongFormat
[static] Value errorCode of a ValidationResult is set to when the postcode is of the wrong format.
PostCodeValidator
  ERROR_WRONG_LENGTH : String = wrongLength
[static] Value errorCode of a ValidationResult is set to when the postcode is of the wrong length.
PostCodeValidator
  FORMAT_COUNTRY_CODE : String = C
[static] Symbol used in postcode formats representing a letter of a country code.
PostCodeValidator
  FORMAT_LETTER : String = A
[static] Symbol used in postcode formats representing a single character.
PostCodeValidator
  FORMAT_NUMBER : String = N
[static] Symbol used in postcode formats representing a single digit.
PostCodeValidator
  FORMAT_SPACERS : String = -
[static] Valid spacer character in postcode formats.
PostCodeValidator
Protected Constants
 ConstantDefined By
 InheritedDECIMAL_DIGITS : String = 0123456789
[static] A String containing the decimal digits 0 through 9.
Validator
 InheritedROMAN_LETTERS : String = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
[static] A string containing the upper- and lower-case letters of the Roman alphabet ("A" through "Z" and "a" through "z").
Validator
Property Detail
countryCodeproperty
countryCode:String

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Optional 1 or 2 letter country code in postcode format

The default value is null.


Implementation
    public function get countryCode():String
    public function set countryCode(value:String):void
extraValidationproperty 
public var extraValidation:Function

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

A user supplied method that performs further validation on a postcode.

The user supplied method should have the following signature: function validatePostcode(postcode:String):String

The method is passed the postcode to be validated and should return either:

  1. A null string indicating the postcode is valid.
  2. A non empty string describing why the postcode is invalid.

The error string will be converted into a ValidationResult when doValidation is called by Flex as part of the normal validation process.

formatproperty 
format:String

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Valid postcode format that postcodes will be compaired against.

The format string consists of the letters C, N, A and spaces or hyphens:

The default value is null.


Implementation
    public function get format():String
    public function set format(value:String):void
formatsproperty 
formats:Array

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

An array of valid format strings to compare postcodes against.

Use for locales where more than one format is required. eg en_UK

See format for format of the format strings.

The default value is [].


Implementation
    public function get formats():Array
    public function set formats(value:Array):void
incorrectFormatErrorproperty 
incorrectFormatError:String

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Error message for an incorrect format string.

The default value is "The postcode format string is incorrect".


Implementation
    public function get incorrectFormatError():String
    public function set incorrectFormatError(value:String):void
invalidCharErrorproperty 
invalidCharError:String

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Error message when the post code contains invalid characters.

The default value is "The postcode code contains invalid characters.".


Implementation
    public function get invalidCharError():String
    public function set invalidCharError(value:String):void
wrongFormatErrorproperty 
wrongFormatError:String

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Error message for an incorrectly formatted postcode.

The default value is "The postcode code must be correctly formatted.".


Implementation
    public function get wrongFormatError():String
    public function set wrongFormatError(value:String):void
wrongLengthErrorproperty 
wrongLengthError:String

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Error message for an invalid postcode.

The default value is "The postcode is invalid.".


Implementation
    public function get wrongLengthError():String
    public function set wrongLengthError(value:String):void
Constructor Detail
PostCodeValidator()Constructor
public function PostCodeValidator()

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Constructor.

Method Detail
doValidation()method
override protected function doValidation(value:Object):Array

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Override of the base class doValidation() method to validate a postcode.

You do not call this method directly; Flex calls it as part of performing a validation. If you create a custom Validator class, you must implement this method.

Parameters

value:Object — Object to validate.

Returns
Array — An Array of ValidationResult objects, with one ValidationResult object for each field examined by the validator.
errorsToLocale()method 
public function errorsToLocale(locale:String):Boolean

Sets the error strings to be from a another locale.

When validating other countries postcode you may want to set the validation message to be from that country but not change the applications locale.

To work the locale must be in the locale chain.

Parameters

locale:String — locale to obtain region from.

Returns
Boolean — True if error message have been changed otherwise false.
suggestCountryCode()method 
public function suggestCountryCode(locale:String = null):String

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Sets the suggested country code for for a given locale.

If no locale is supplied the default locale is used.

Currently only a limited set of locales are supported.

Parameters

locale:String (default = null) — Locale to obtain country code for.

Returns
String — The suggested code or an null string if the locale is not supported or has no country code.
suggestFormat()method 
public function suggestFormat(locale:String = null, changeErrors:Boolean = false):Array

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Sets the suggested postcode formats for a given locale.

If no locale is supplied the default locale is used.

Currently only a limited set of locales are supported.

Parameters

locale:String (default = null) — Locale to obtain formats for.
 
changeErrors:Boolean (default = false) — If true change error message to match local.

Returns
Array — The suggested format (an array of strings) or an empty array if the locale is not supported.
validatePostCode()method 
public static function validatePostCode(validator:PostCodeValidator, postCode:String, baseField:String):Array

Language Version : ActionScript 3.0
Product Version : ApacheFlex 4.8
Runtime Versions : AIR 1.0, Flash Player 10.2

Convenience method for calling a validator. Each of the standard Flex validators has a similar convenience method.

Parameters

validator:PostCodeValidator — The PostCodeValidator instance.
 
postCode:String — A field to validate.
 
baseField:String — Text representation of the subfield specified in the value parameter. For example, if the value parameter specifies value.postCode, the baseField value is "postCode".

Returns
Array — An Array of ValidationResult objects, with one ValidationResult object for each field examined by the validator.

See also

Constant Detail
ERROR_INCORRECT_FORMATConstant
public static const ERROR_INCORRECT_FORMAT:String = incorrectFormat

Value errorCode of a ValidationResult is set to when the format contains unknown format characters.

ERROR_INVALID_CHARConstant 
public static const ERROR_INVALID_CHAR:String = invalidChar

Value errorCode of a ValidationResult is set to when the postcode contains an invalid charater.

ERROR_WRONG_FORMATConstant 
public static const ERROR_WRONG_FORMAT:String = wrongFormat

Value errorCode of a ValidationResult is set to when the postcode is of the wrong format.

ERROR_WRONG_LENGTHConstant 
public static const ERROR_WRONG_LENGTH:String = wrongLength

Value errorCode of a ValidationResult is set to when the postcode is of the wrong length.

FORMAT_COUNTRY_CODEConstant 
public static const FORMAT_COUNTRY_CODE:String = C

Symbol used in postcode formats representing a letter of a country code.

FORMAT_LETTERConstant 
public static const FORMAT_LETTER:String = A

Symbol used in postcode formats representing a single character.

FORMAT_NUMBERConstant 
public static const FORMAT_NUMBER:String = N

Symbol used in postcode formats representing a single digit.

FORMAT_SPACERSConstant 
public static const FORMAT_SPACERS:String = -

Valid spacer character in postcode formats.