The DateValidator class validates that a String, Date, or Object contains a proper date and matches a specified format. Users can enter a single digit or two digits for month, day, and year. By default, the validator ensures the following formats:

  • The month is between 1 and 12 (or 0-11 for Date objects)
  • The day is between 1 and 31
  • The year is a number

You can specify the date in the DateValidator class in two ways:

  • A single String containing the date - Use the source and property properties to specify the String. The String can contain digits and the formatting characters specified by the allowedFormatChars property, which include the "/-. " characters. By default, the input format of the date in a String field is "MM/DD/YYYY" where "MM" is the month, "DD" is the day, and "YYYY" is the year. You can use the inputFormat property to specify a different format.
  • A Date object.
  • An anonymous structure or multiple fields containing the day, month, and year. Use all of the following properties to specify the day, month, and year inputs: daySource, dayProperty, monthSource, monthProperty, yearSource, and yearProperty.

Static methods

staticvalidateDate(validator:DateValidator, value:Dynamic, baseField:String):Array<ValidationResult>

Convenience method for calling a validator from within a custom validation function. Each of the standard Flex validators has a similar convenience method.

Parameters:

validator

The DateValidator instance.

value

A field to validate.

baseField

Text representation of the subfield specified in the value parameter. For example, if the value parameter specifies value.date, the baseField value is "date".

Returns:

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

See also:

Constructor

new()

Constructor.

Variables

allowedFormatChars:String

The set of formatting characters allowed for separating the month, day, and year values.

dayListener:IValidatorListener

The component that listens for the validation result for the day subfield. If none is specified, use the value specified for the daySource property.

dayProperty:String

Name of the day property to validate. This property is optional, but if you specify the daySource property, you should specify either dayProperty or dayValueFunction as well.

See also:

  • dayValueFunction

daySource:Dynamic

Object that contains the value of the day field. If you specify a value for this property, you must also specify a value for either the dayProperty property or the dayValueFunction property. Do not use this property if you set the source and property (or valueFunction) properties.

See also:

  • dayProperty

  • dayValueFunction

formatError:String

Error message when the inputFormat property is not in the correct format.

includeFormatInError:Bool

If true the date format is shown in some validation error messages. Setting to false changes all DateValidators.

inputFormat:String

The date format to validate the value against. "MM" is the month, "DD" is the day, and "YYYY" is the year. This String is case-sensitive.

invalidCharError:String

Error message when there are invalid characters in the date.

monthListener:IValidatorListener

The component that listens for the validation result for the month subfield. If none is specified, use the value specified for the monthSource property.

monthProperty:String

Name of the month property to validate. This property is optional, but if you specify the monthSource property, you should specify either monthProperty or monthValueFunction as well.

See also:

  • monthValueFunction

monthSource:Dynamic

Object that contains the value of the month field. If you specify a value for this property, you must also specify a value for either the monthProperty property or the monthValueFunction property. Do not use this property if you set the source and property (or valueFunction) properties.

See also:

  • monthProperty

  • monthValueFunction

validateAsString:Bool

Determines how to validate the value. If set to true, the validator evaluates the value as a String, unless the value has a month, day, or year property. If false, the validator evaluates the value as a Date object.

wrongDayError:String

Error message when the day is invalid.

wrongLengthError:String

Error message when the length of the date doesn't match that of the inputFormat property.

wrongMonthError:String

Error message when the month is invalid.

wrongYearError:String

Error message when the year is invalid.

yearListener:IValidatorListener

The component that listens for the validation result for the year subfield. If none is specified, use the value specified for the yearSource property.

yearProperty:String

Name of the year property to validate. This property is optional, but if you specify the yearSource property, you should specify either yearProperty or yearValueFunction as well.

See also:

  • yearValueFunction

yearSource:Dynamic

Object that contains the value of the year field. If you specify a value for this property, you must also specify a value for either the yearProperty property or the yearValueFunction property. Do not use this property if you set the source and property (or valueFunction) properties.

See also:

  • yearProperty

  • yearValueFunction

dayValueFunction:() ‑> Dynamic

A function that returns the day value to validate. It's recommended to use dayValueFunction instead of dayProperty because reflection is used with dayProperty, which could result in issues if Dead Code Elimination (DCE) is enabled.

monthValueFunction:() ‑> Dynamic

A function that returns the day value to validate. It's recommended to use monthValueFunction instead of monthProperty because reflection is used with monthProperty, which could result in issues if Dead Code Elimination (DCE) is enabled.

yearValueFunction:() ‑> Dynamic

A function that returns the day value to validate. It's recommended to use yearValueFunction instead of yearProperty because reflection is used with yearProperty, which could result in issues if Dead Code Elimination (DCE) is enabled.

Inherited Variables

Defined by Validator

enabled:Bool

Setting this value to false will stop the validator from performing validation. When a validator is disabled, it dispatch no events, and the validate() method returns null. *

listener:Dynamic

Specifies the validation listener.

If you do not specify a listener, Flex uses the value of the source property. After Flex determines the source component, it changes the border color of the component, displays an error message for a failure, or hides any existing error message for a successful validation.

property:String

A String specifying the name of the property of the source object that contains the value to validate. Setting property is optional, but if you specify source, you should set a value for either property or valueFunction as well.

Reading the property uses reflection, which may not work if Dead Code Elimination (DCE) is enabled. The property property is included for backwards compatibility with the Flex API, but the new valueFunction is now recommended instead.

See also:

  • valueFunction

required:Bool

If true, specifies that a missing or empty value causes a validation error.

requiredFieldError:String

Error message when a value is missing and the required property is true.

source:Dynamic

Specifies the object containing the property to validate. Set this to an instance of a component or a data model. You use data binding syntax in MXML to specify the value. This property supports dot-delimited Strings for specifying nested properties.

If you specify a value to the source property, then you should specify a value to either the property property or the valueFunction property as well. The source property is optional.

See also:

  • property

  • valueFunction

trigger:IEventDispatcher

Specifies the component generating the event that triggers the validator. If omitted, by default Flex uses the value of the source property. When the trigger dispatches a triggerEvent, validation executes.

triggerEvent:String

Specifies the event that triggers the validation. If omitted, Flex uses the valueCommit event. Flex dispatches the valueCommit event when a user completes data entry into a control. Usually this is when the user removes focus from the component, or when a property value is changed programmatically. If you want a validator to ignore all events, set triggerEvent to the empty string ("").

valueFunction:() ‑> Dynamic

A function that returns the value to validate. It's recommended to use valueFunction instead of property because reflection is used with property, which could result in issues if Dead Code Elimination (DCE) is enabled.

Inherited Methods

Defined by Validator

@:value({ suppressEvents : false, value : null })validate(?value:Dynamic, suppressEvents:Bool = false):ValidationResultEvent

Performs validation and optionally notifies the listeners of the result.

Parameters:

value

Optional value to validate. If null, then the validator uses the source and property properties to determine the value. If you specify this argument, you should also set the listener property to specify the target component for any validation error messages.

suppressEvents

If false, then after validation, the validator will notify the listener of the result.

Returns:

A ValidationResultEvent object containing the results of the validation. For a successful validation, the ValidationResultEvent.results Array property is empty. For a validation failure, the ValidationResultEvent.results Array property contains one ValidationResult object for each field checked by the validator, both for fields that failed the validation and for fields that passed. Examine the ValidationResult.isError property to determine if the field passed or failed the validation.

See also: