如何使用Flex NumberFormatter
关键字: flex flex3 numberformatter
<?xml version="1.0"?> <!-- Simple example to demonstrate NumberFormatter. --> <!-- 如何使用Flex NumberFormatter MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.events.ValidationResultEvent; private var vResult:ValidationResultEvent; // Event handler to validate and format input. private function Format():void { vResult = numVal.validate(); if (vResult.type==ValidationResultEvent.VALID) { formattedNumber.text= numberFormatter.format(inputVal.text); } else { formattedNumber.text= ""; } } ]]> </mx:Script> <mx:NumberFormatter id="numberFormatter" precision="4" useThousandsSeparator="true" useNegativeSign="true"/> <mx:NumberValidator id="numVal" source="{inputVal}" property="text" allowNegative="true" domain="real"/> <mx:Panel title="NumberFormatter Example" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter number:"> <mx:TextInput id="inputVal" text="" width="50%"/> </mx:FormItem> <mx:FormItem label="Formatted number (precision=4): "> <mx:TextInput id="formattedNumber" editable="false" width="50%"/> </mx:FormItem> <mx:FormItem> <mx:Button label="Validate and Format" click="Format();"/> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:21
- 浏览 (342)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the ZipCodeValidator. --> <!-- 如何使用Flex ZipCodeValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <mx:ZipCodeValidator source="{zip}" property="text" trigger="{myButton}" triggerEvent="click" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="ZipcodeValidator Example" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter a 5 or 9 digit U.S. Zip code: "> <mx:TextInput id="zip" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate" /> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:10
- 浏览 (54)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0"?> <!-- Simple example to demonstrate the Validator class. --> <!-- 如何使用Flex Validator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ // Import necessary classes. import mx.controls.Alert; import mx.events.ValidationResultEvent; // Event listener for the valid and invalid events. private function handleValid(eventObj:ValidationResultEvent):void { if(eventObj.type==ValidationResultEvent.VALID) // Enable Submit button. submitButton.enabled = true; else submitButton.enabled = false; } // Submit form is everything is valid. private function submitForm():void { Alert.show("Form Submitted!"); } ]]> </mx:Script> <!-- The Validator class defines the required property and the validator events used by all validator subclasses. --> <mx:Validator id="reqValid" required="true" source="{fname}" property="text" valid="handleValid(event)" invalid="handleValid(event)"/> <mx:Panel title="Validator Example" width="100%" height="100%" paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5"> <mx:Form> <mx:Text width="100%" color="blue" text="Enter a value in the Name field before you can submit. The E-mail field is optional."/> <mx:FormItem label="Name: " required="true"> <mx:TextInput id="fname" width="100%"/> </mx:FormItem> <mx:FormItem label="E-mail address: " required="false"> <mx:TextInput id="email" width="100%"/> </mx:FormItem> <mx:FormItem> <mx:Button id="submitButton" enabled="false" label="Submit" click="submitForm();"/> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:09
- 浏览 (562)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate StringValidator. --> <!-- 如何使用Flex StringValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <mx:StringValidator source="{fname}" property="text" tooShortError="This string is shorter than the minimum allowed length of 4. " tooLongError="This string is longer than the maximum allowed length of 20." minLength="4" maxLength="20" trigger="{myButton}" triggerEvent="click" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="StringValidator Example" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter a name between 4 and 20 characters: "> <mx:TextInput id="fname" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate" /> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:08
- 浏览 (403)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate SocialSecurityValidator. --> <!-- 如何使用Flex SocialSecurityValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <mx:SocialSecurityValidator source="{ssn}" property="text" trigger="{myButton}" triggerEvent="click" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="Social Security Validator Panel" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter Social Security number: "> <mx:TextInput id="ssn" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate" /> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:05
- 浏览 (36)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0"?> <!-- Simple example to demonstrate the RegExpValidator. --> <!-- 如何使用Flex RegExpValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ import mx.events.ValidationResultEvent; import mx.validators.*; // Write the results to the private function handleResult(eventObj:ValidationResultEvent):void { if (eventObj.type == ValidationResultEvent.VALID) { // For valid events, the results Array contains // RegExpValidationResult objects. var xResult:RegExpValidationResult; reResults.text=""; for (var i:uint = 0; i < eventObj.results.length; i++) { xResult = eventObj.results[i]; reResults.text=reResults.text + xResult.matchedIndex + " " + xResult.matchedString + "/n"; } } else { reResults.text=""; } } ]]> </mx:Script> <mx:RegExpValidator id="regExpV" source="{regex_text}" property="text" flags="g" expression="{regex.text}" valid="handleResult(event)" invalid="handleResult(event)" trigger="{myButton}" triggerEvent="click"/> <mx:Panel title="RegExpValidator Example" width="95%" height="95%" paddingTop="5" paddingLeft="5" paddingRight="5" paddingBottom="5"> <mx:Text width="100%" text="Instructions:"/> <mx:Text width="100%" text="1. Enter text to search. By default, enter a string containing the letters ABC in sequence followed by any digit."/> <mx:Text width="100%" text="2. Enter the regular expression. By default, enter ABC/d."/> <mx:Text width="100%" text="3. Click the Button control to trigger the validation."/> <mx:Text width="100%" text="4. The results show the index in the text where the matching pattern begins, and the matching pattern. "/> <mx:Form> <mx:FormItem label="Enter text: "> <mx:TextInput id="regex_text" text="xxxxABC4xxx" width="100%"/> </mx:FormItem> <mx:FormItem label="Enter regular expression: "> <mx:TextInput id="regex" text="ABC/d" width="100%"/> </mx:FormItem> <mx:FormItem label="Results: "> <mx:TextInput id="reResults" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate"/> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:05
- 浏览 (354)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the PhoneNumberValidator. --> <!-- 如何使用Flex PhoneNumberValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <mx:PhoneNumberValidator source="{phone}" property="text" trigger="{myButton}" triggerEvent="click" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="Phone Number Validator Panel" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter 10-digit phone number: "> <mx:TextInput id="phone" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate" /> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:04
- 浏览 (97)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the NumberValidator. --> <!-- 如何使用Flex NumberValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <mx:NumberValidator source="{age}" property="text" integerError="Enter Integer value" minValue="18" maxValue="50" domain="int" trigger="{myButton}" triggerEvent="click" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="NumberValidator Example" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter an age between 18 and 50: "> <mx:TextInput id="age" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate" /> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:04
- 浏览 (405)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the EmailValidator. --> <!-- 如何使用Flex EmailValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <mx:EmailValidator source="{email}" property="text" trigger="{myButton}" triggerEvent="click" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="EmailValidator Example" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter an e-mail address: "> <mx:TextInput id="email" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate" /> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:03
- 浏览 (199)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the DateValidator. --> <!-- 如何使用Flex DateValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <mx:Model id="CheckModel"> <dateInfo> <DOB>{dob.text}</DOB> </dateInfo> </mx:Model> <mx:DateValidator source="{dob}" property="text" allowedFormatChars="/" trigger="{myButton}" triggerEvent="click" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="DateValidator Example" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter date of birth (mm/dd/yyyy): "> <mx:TextInput id="dob" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate" /> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:02
- 浏览 (287)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0" encoding="utf-8"?> <!-- Simple example to demonstrate the CurrencyValidator. --> <!-- 如何使用Flex CurrencyValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <mx:CurrencyValidator source="{priceUS}" property="text" precision="2" trigger="{myButton}" triggerEvent="click" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="CurrencyValidator Example" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form> <mx:FormItem label="Enter a U.S. dollar amount: "> <mx:TextInput id="priceUS" width="100%"/> </mx:FormItem> <mx:FormItem > <mx:Button id="myButton" label="Validate"/> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>
- 13:02
- 浏览 (42)
- 评论 (0)
- 分类: Flex Validators
- 收藏
<?xml version="1.0"?> <!-- Simple example to demonstrate the CreditCardValidator. --> <!-- 如何使用Flex CreditCardValidator MyShareBook.cn 翻译 --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> import mx.controls.Alert; </mx:Script> <!-- Define model for the credit card data. --> <mx:Model id="creditcard"> <card> <cardType>{cardTypeCombo.selectedItem.data}</cardType> <cardNumber>{cardNumberInput.text}</cardNumber> </card> </mx:Model> <mx:CreditCardValidator id="ccV" cardTypeSource="{creditcard}" cardTypeProperty="cardType" cardNumberSource="{creditcard}" cardNumberProperty="cardNumber" trigger="{myButton}" triggerEvent="click" cardTypeListener="{cardTypeCombo}" cardNumberListener="{cardNumberInput}" valid="Alert.show('Validation Succeeded!');"/> <mx:Panel title="CreditCardValidator Example" width="75%" height="75%" paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10"> <mx:Form id="creditCardForm"> <mx:FormItem label="Card Type"> <mx:ComboBox id="cardTypeCombo"> <mx:dataProvider> <mx:Object label="American Express" data="American Express"/> <mx:Object label="Diners Club" data="Diners Club"/> <mx:Object label="Discover" data="Discover"/> <mx:Object label="MasterCard" data="MasterCard"/> <mx:Object label="Visa" data="Visa"/> </mx:dataProvider> </mx:ComboBox> </mx:FormItem> <mx:FormItem label="Credit Card Number"> <mx:TextInput id="cardNumberInput"/> </mx:FormItem> <mx:FormItem> <mx:Button id="myButton" label="Check Credit"/> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Application>