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
Dateobjects) - 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
Stringcontaining the date - Use thesourceandpropertyproperties to specify the String. The String can contain digits and the formatting characters specified by theallowedFormatCharsproperty, 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 theinputFormatproperty to specify a different format. - A
Dateobject. - 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, andyearProperty.
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 |
Returns:
An Array of ValidationResult objects, with one ValidationResult object for each field examined by the validator.
See also:
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:
dayPropertydayValueFunction
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.
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:
monthPropertymonthValueFunction
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.
wrongLengthError:String
Error message when the length of the date
doesn't match that of the inputFormat property.
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:
yearPropertyyearValueFunction
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.