Package | mx.validators |
Class | public class PostCodeValidator |
Inheritance | PostCodeValidator ![]() |
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 | ||
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 | ||
wrongFormatError : String
Error message for an incorrectly formatted postcode. | PostCodeValidator | ||
wrongLengthError : String
Error message for an invalid postcode. | PostCodeValidator |
Method | Defined By | ||
---|---|---|---|
Constructor. | PostCodeValidator | ||
suggestCountryCode(locale:String = null):String
Sets the suggested country code for for a given locale. | PostCodeValidator | ||
suggestFormat(locale:String = null):Array
Sets the suggested postcode formats for a given locale. | PostCodeValidator | ||
validatePostCode(validator:PostCodeValidator, postCode:String, baseField:String):Array [static]
Convenience method for calling a validator. | PostCodeValidator |
Method | Defined By | ||
---|---|---|---|
doValidation(value:Object):Array [override]
Override of the base class doValidation() method
to validate a postcode. | PostCodeValidator |
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.
|
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 suplied the default locale is used.
Currenly 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):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 suplied the default locale is used.
Currenly only a limited set of locales are supported.
Parameters
locale:String (default = null ) — Locale to obtain formats for.
|
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.