Apache Flex 4.16.1 API Reference | All Packages | All Classes | Index | Frames No Frames |
PostCodeValidator

Package | org.apache.flex.validators
Class | public class PostCodeValidator
Inheritance | PostCodeValidator Validator 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

- CC or C is the country code (required for some postcodes).
- N is a number 0-9.
- A is a letter A-Z or a-z.

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 Syntax Show MXML Syntax
Hide 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
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | countryCode : String Optional 1 or 2 letter country code in postcode format | PostCodeValidator
|  | enabled : 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
|  | listener : Object Specifies the validation listener. | Validator
|  | property : String A String specifying the name of the property of the source object that contains the value to validate. | Validator
|  | required : Boolean If true, specifies that a missing or empty value causes a validation error. | Validator
|  | requiredFieldError : String Error message when a value is missing and the required property is true. | Validator
|  | source : Object Specifies the object containing the property to validate. | Validator
|  | trigger : IEventDispatcher Specifies the component generating the event that triggers the validator. | Validator
|  | triggerEvent : 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
Hide Inherited Protected Properties
Show Inherited Protected Properties

| Property | Defined By
--- | --- | ---
|  | actualListeners : Array [read-only] Contains an Array of listener objects, if any, or the source object. | Validator
|  | actualTrigger : IEventDispatcher [read-only] Contains the trigger object, if any, or the source object. | Validator
|  | resourceManager : IResourceManager [read-only] A reference to the object which manages all of the application's localized resources. | Validator
|  | subFields : Array An Array of Strings containing the names for the properties contained in the value Object passed to the validate() method. | Validator

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | PostCodeValidator() Constructor. | PostCodeValidator
|  | errorsToLocale(locale:String):Boolean Sets the error strings to be from a another locale. | PostCodeValidator
|  | 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
|  | validate(value:Object = null, suppressEvents:Boolean = false):ValidationResultEvent Performs validation and optionally notifies the listeners of the result. | Validator
|  | 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
Show Inherited Protected Methods
Show Inherited Protected Methods

| Method | Defined By
--- | --- | ---
|  | addListenerHandler():void 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
|  | getValueFromSource():Object Returns the Object to validate. | Validator
|  | handleResults(errorResults:Array):ValidationResultEvent Returns a ValidationResultEvent from the Array of error results. | Validator
|  | isRealValue(value:Object):Boolean Returns true if value is not null. | Validator
|  | removeListenerHandler():void Disconnects all of the listeners for the valid and invalid events dispatched from the validator. | Validator
|  | resourcesChanged():void 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
Hide Inherited Events
Show Inherited Events

| Event | Summary | Defined By
--- | --- | --- | ---
|  | invalid | Dispatched when validation fails. | Validator
|  | valid | Dispatched when validation succeeds. | Validator

Public Constants

| Constant | Defined 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
Hide Inherited Protected Constants
Show Inherited Protected Constants

| Constant | Defined By
--- | --- | ---
|  | DECIMAL_DIGITS : String = 0123456789 [static] A String containing the decimal digits 0 through 9. | Validator
|  | ROMAN_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

countryCode | property

`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`

extraValidation | property |

`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.

format | property |

`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:

- CC or C is country code (required for some postcodes).
- N is a number 0-9.
- A is a letter A-Z or a-z.

The default value is `null`.

Implementation
`public function get format():String`
`public function set format(value:String):void`

formats | property |

`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`

incorrectFormatError | property |

`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`

invalidCharError | property |

`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`

wrongFormatError | property |

`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`

wrongLengthError | property |

`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

mx.validators.ValidationResult
Constant Detail

ERROR_INCORRECT_FORMAT | Constant

`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_CHAR | Constant |

`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_FORMAT | Constant |

`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_LENGTH | Constant |

`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_CODE | Constant |

`public static const FORMAT_COUNTRY_CODE:String = C`

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

FORMAT_LETTER | Constant |

`public static const FORMAT_LETTER:String = A`

Symbol used in postcode formats representing a single character.

FORMAT_NUMBER | Constant |

`public static const FORMAT_NUMBER:String = N`

Symbol used in postcode formats representing a single digit.

FORMAT_SPACERS | Constant |

`public static const FORMAT_SPACERS:String = -`

Valid spacer character in postcode formats.

Wed Nov 15 2017, 09:50 AM +01:00