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 |
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.
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
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 |
Method | Defined By | ||
---|---|---|---|
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 |
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 |
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 |
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
.
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:
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:
The default value is null
.
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 []
.
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"
.
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."
.
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."
.
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."
.
public function get wrongLengthError():String
public function set wrongLengthError(value:String):void
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.
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.
|
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.
|
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.
|
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.
|
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" .
|
Array — An Array of ValidationResult objects, with one ValidationResult
object for each field examined by the validator.
|
See also
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.