简体   繁体   中英

Flex 4 - How to format and validate DateField TextInput?

I have a DateField with editable = true. Now i want to validate the DateField TextInput. If the user enter the value like this "200001/12/12", it has to be display the error message. How can i do it?

If you are using your own date format, you need to make the validation by your own (custom function). Otherwise, you can use a DateValidator and call validate on DateField change:

<mx:DateValidator id="dateValidator" source="{myDate}" property="text" requiredFieldError="You must choose a date" />
<mx:DateField id="myDate" focusOut="dateValidator.validate()" />

This is a basic example, maybe you will need to tweak it a little. You can also use the reference (it has a working example at the bottom):

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/validators/DateValidator.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM