The NumberValidator class ensures that a String represents a valid number. It can ensure that the input falls within a given range (specified by minValue and maxValue), is an integer (specified by domain), is non-negative (specified by allowNegative), and does not exceed the specified precision. The validator correctly validates formatted numbers (e.g., "12,345.67") and you can customize the thousandsSeparator and decimalSeparator properties for internationalization.

Static methods

staticvalidateNumber(validator:NumberValidator, 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.



The NumberValidator instance.


A field to validate.


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


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

See also:






Specifies whether negative numbers are permitted. Valid values are true or false.


Error message when the decimal separator character occurs more than once.


The character used to separate the whole from the fractional part of the number. Cannot be a digit and must be distinct from the thousandsSeparator.


Type of number to be validated. Permitted values are "real" and "int".

In Haxe, you can use the following constants to set this property: NumberValidatorDomainType.REAL or NumberValidatorDomainType.INT.


Error message when the value exceeds the maxValue property.


Error message when the number must be an integer, as defined by the domain property.


Error message when the value contains invalid characters.


Error message when the value contains invalid format characters, which means that it contains a digit or minus sign (-) as a separator character, or it contains two or more consecutive separator characters.


Error message when the value is less than minValue.


Maximum value for a valid number. A value of Math.NaN means there is no maximum.


Minimum value for a valid number. A value of Math.NaN means there is no minimum.


Error message when the value is negative and the allowNegative property is false.


The maximum number of digits allowed to follow the decimal point. Can be any nonnegative integer. Note: Setting to 0 has the same effect as setting domain to "int". A value of -1 means it is ignored.


Error message when the value has a precision that exceeds the value defined by the precision property.


Error message when the thousands separator is in the wrong location.


The character used to separate thousands in the whole part of the number. Cannot be a digit and must be distinct from the decimalSeparator.

Inherited Variables

Defined by Validator


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


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.


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


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


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


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


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.


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.



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.


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


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: