<mx:DateValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:DateValidator allowedFormatChars="/\-. " dayListener="Object specified by daySource" dayProperty="No default" daySource="No default" formatError= "Configuration error: Incorrect formatting string." inputFormat="MM/DD/YYYY" invalidCharError="The date contains invalid characters." monthListener="Object specified by monthSource" monthProperty="No default" monthSource="No default" validateAsString="true|false" wrongDayError="Enter a valid day for the month." wrongLengthError="Type the date in the format inputFormat." wrongMonthError="Enter a month between 1 and 12." wrongYearError="Enter a year between 0 and 9999." yearListener="Object specified by yearSource" yearProperty="No default" yearSource="No default" />]]>
您可以按两种方式在 DateValidator 类中指定日期:
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 validator 类,则必须实现此方法。
<mx:ZipCodeValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:ZipCodeValidator allowedFormatChars=" -" domain="US Only | US or Canada | Canada Only" invalidCharError="The ZIP code contains invalid characters." invalidDomainError="The domain parameter is invalid. It must be either 'US Only', 'Canada Only', or 'US or Canada'." wrongCAFormatError="The Canadian postal code must be formatted 'A1B 2C3'." wrongLengthError="The ZIP code must be 5 digits or 5+4 digits." wrongUSFormatError="The ZIP+4 code must be formatted '12345-6789'." />]]>
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
在 ActionScript 中,可以使用以下常量来设置此属性:
该接口可以用来验证在 mx 和 spark 命名空间中定义的多个数据类型,例如数字、货币、电话号码和邮政编码等。mx:Validator 类和 spark:GlobaliationValidatorBase 类实现该接口。这些类中的 validateAll() 方法使用该接口类型调用多个 validator 对象上的 validate() 方法。
将此值设置为
<mx:CurrencyValidator>
tag
inherits all of the tag properties of its superclass,
and adds the following tag properties:
<mx:CurrencyValidator alignSymbol="left|right|any" allowNegative="true|false" currencySymbol="$" currencySymbolError="The currency symbol occurs in an invalid location." decimalPointCountError="The decimal separator can occur only once." decimalSeparator="." exceedsMaxError="The amount entered is too large." invalidCharError="The input contains invalid characters." invalidFormatCharsError="One of the formatting parameters is invalid." lowerThanMinError="The amount entered is too small." maxValue="NaN" minValue="NaN" negativeError="The amount may not be negative." precision="2" precisionError="The amount entered has too many digits beyond the decimal point." separationError="The thousands separator must be followed by three digits." thousandsSeparator="," />]]>
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
<mx:StringValidator>
tag
inherits all of the tag attributes of its superclass,
and add the following tag attributes:
<mx:StringValidator maxLength="NaN" minLength="NaN" tooLongError="This string is longer than the maximum allowed length. This must be less than {0} characters long." tooShortError="This string is shorter than the minimum allowed length. This must be at least {0} characters long." />]]>
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
<mx:RegExpValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:RegExpValidator expression="No default" flags="No default" noExpressionError="The expression is missing." noMatchError="The field is invalid." />]]>
如果验证程序可以在要验证的字段中找到正则表达式的匹配项,则验证成功。如果验证程序找不到匹配项,则会出现验证错误。
RegExpValidator 类分派
但是,对于
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
<mx:NumberValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:NumberValidator allowNegative="true|false" decimalPointCountError="The decimal separator can only occur once." decimalSeparator="." domain="real|int" exceedsMaxError="The number entered is too large." integerError="The number must be an integer." invalidCharError="The input contains invalid characters." invalidFormatCharsError="One of the formatting parameters is invalid." lowerThanMinError="The amount entered is too small." maxValue="NaN" minValue="NaN" negativeError="The amount may not be negative." precision="-1" precisionError="The amount entered has too many digits beyond the decimal point." separationError="The thousands separator must be followed by three digits." thousandsSeparator="," />]]>
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
在 ActionScript 中,您可以使用下列常量来设置此属性:
<mx:PhoneNumberValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:PhoneNumberValidator allowedFormatChars="()- .+" invalidCharError="Your telephone number contains invalid characters." minDigits="10" wrongLengthError="Your telephone number must contain at least 10 digits." />]]>
通常不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
<mx:EmailValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:EmailValidator invalidCharError="Your e-mail address contains invalid characters." invalidDomainError= "The domain in your e-mail address is incorrectly formatted." invalidIPDomainError="The IP domain in your e-mail address is incorrectly formatted." invalidPeriodsInDomainError="The domain in your e-mail address has consecutive periods." missingAtSignError="An at sign (&64;) is missing in your e-mail address." missingPeriodInDomainError="The domain in your e-mail address is missing a period." missingUsernameError="The username in your e-mail address is missing." tooManyAtSignsError="Your e-mail address contains too many &64; characters." />]]>
如果用方括号括住 IP 域名,则可以使用它们;例如,myname@[206.132.22.1]。可以使用从 0 到 255 的各个 IP 数字。
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
但是,对于
ValidationResultEvent 类定义传递到
<mx:Validator enabled="true|false" listener="Value of the source property" property="No default" required="true|false" requiredFieldError="This field is required." source="No default" trigger="Value of the source property" triggerEvent="valueCommit" />]]>
如果创建 validator 类的子类,则必须覆盖此方法。
在下列情形中分派此事件:设置 ResourceManager 的
子类应覆盖此方法,并在调用
验证多个数据字段的 Validator 类的子类(如 CreditCardValidator 和 DateValidator)应该在其构造函数中分配这一属性。
如果不指定侦听器,则 Flex 使用
<mx:CreditCardValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:CreditCardValidator allowedFormatChars=" -" cardNumberListener="Object specified by cardNumberSource" cardNumberProperty="No default" cardNumberSource="No default" cardTypeListener="Object specified by cardTypeSource" cardTypeProperty="No default" cardTypeSource="No default" invalidCharError= "Invalid characters in your credit card number. (Enter numbers only.)" invalidNumberError="The credit card number is invalid." noNumError="No credit card number is specified." noTypeError="No credit card type is specified or the type is not valid." wrongLengthError="Your credit card number contains the wrong number of digits." wrongTypeError="Incorrect card type is specified." />]]>
您可以按两种方式指定 CreditCardValidator 的输入:
在 MXML 中,使用以下值:
在 ActionScript 中,使用静态常量
为了执行验证,它使用以下指导原则:
长度:
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
在 MXML 中,有效值为:
在 ActionScript 中,可以使用以下常量来设置此属性:
<mx:SocialSecurityValidator>
tag
inherits all of the tag attributes of its superclass,
and adds the following tag attributes:
<mx:SocialSecurityValidator allowedFormatChars=" -" invalidCharError="You entered invalid characters in your Social Security number." wrongFormatError="The Social Security number must be 9 digits or in the form NNN-NN-NNNN." zeroStartError="Invalid Social Security number; the number cannot start with 000." />]]>
不要直接调用此方法;Flex 会在执行验证的过程中调用它。如果创建自定义 Validator 类,则必须实现此方法。
您通常通过向验证程序分配事件侦听器来处理由验证程序分派的
您可以使用
若要清除验证错误,请为
请注意,为