Data Access and Interconnectivity / Validating Data:
http://livedocs.adobe.com/flex/3/html/help.html?content=validators_2.html
引用
In typical client-server environments, data validation occurs on the server after data is submitted to it from the client. One advantage of using Flex validators is that they execute on the client, which lets you validate input data before transmitting it to the server.
By using Flex validators, you eliminate the need to transmit data to and receive error messages back from the server, which improves the overall responsiveness of your application.
Note: Flex validators do not eliminate the need to perform data validation on the server, but provide a mechanism for improving performance by performing some data validation on the client.
上面的摘录说的很清楚:flex validator为我们提供了一种不需要调用服务器端,只在flex client端的验证方式。
但在验证体系中,是否还有调用服务器端的必要那?答案是有的!比如说做添加操作时,某业务主键的是否重复验证,最好就是在点击提交按钮后,调用服务器端,验证所输入的业务主键值是否重复,而不应该使用之前取过的这样一个业务主键list。这样的验证该怎么办那?只能通过扩展flex validator,使其支持远程方法调用来做了:
Showing errors for backend validations:
http://www.actionscript.org/forums/showthread.php3?t=173275
Handle client and server validation with Flex 3?
http://stackoverflow.com/questions/5897917/handle-client-and-server-validation-with-flex-3
custom validator against remote object:
http://stackoverflow.com/questions/3979592/custom-validator-against-remote-object
flex : creating custom validators:
http://flexscript.wordpress.com/2008/09/22/flex-creating-custom-validators/
引用
All standard validators components inherits from the base of mx.Validators.Validator class. To create a custom validator need to work with extending the Validator class. The creation of custom validator includes following steps;
A) Create a class which extends mx.Validators.Validator.
B) Class must override doValidation() method.
C) Overridden doValidation() method should accept a parameter of type Object.
D) Overridden doValidation() method should return an Array.
If the validation of a condition against given object doesn’t succeed, then doValidation() method returns an array containing objects of ValidationResult. If doValidation() method does succeed then method returns an empty array.
Using Flex 4 / Enhancing usability / Validating Data -> Using validators:
http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf60efb-7fdd.html
引用
trigger Specifies the component generating the event that triggers the validator. If omitted, by default Flex uses the value of the source property.
triggerEvent Specifies the event that triggers the validation. If omitted, Flex uses the valueCommit event. Flex dispatches the valueCommit event whenever the value of a control changes. 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 an empty string (""). For information on specific validator classes, see Using standard validators.
Validating data by using custom validators:
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf68c0f-7ffb.html
引用
About overriding the doValidation() method
Your custom validator class must contain an override of the protected Validator.doValidation() method that takes a single argument, value, of type Object, and returns an Array of ValidationResult objects. You return one ValidationResult object for each field that the validator examines and that fails the validation. For fields that pass the validation, you omit the ValidationResult object.
You do not have to create a ValidationResult object for fields that validate successfully. Flex creates those ValidationResult objects for you.
The base Validator class implements the logic to handle required fields by using the required property. When set to true, this property specifies that a missing or empty value in a user-interface control causes a validation error. To disable this verification, set this property to false.
In the doValidation() method of your validator class, you typically call the base class’s doValidation() method to perform the verification for a required field. If the user did not enter a value, the base class issues a validation error stating that the field is required.
The remainder of the doValidation() method contains your custom validation logic.
Example: Validating multiple fields:
http://livedocs.adobe.com/flex/3/html/help.html?content=createvalidators_4.html#184524
Flex 3 Custom validation of grouped input fields:
http://flexmaster.blog.co.in/2010/06/16/flex-drag-and-drop-the-definitive-tutorial/
通过Validator的validateAll方法对页面所有验证在点击提交按钮时做集中验证:
Validating Flex forms using the Validator classes:
http://blog.flexexamples.com/2007/08/13/validating-flex-forms-using-the-validator-classes/
Using the Validators.validateAll() method to validate a form:
http://blog.flexexamples.com/2007/08/02/using-the-validatorsvalidateall-method-to-validate-a-form/
Working with validation events:
http://livedocs.adobe.com/flex/3/html/help.html?content=validators_6.html
引用
<?xml version="1.0"?>
<!-- validators\ValEventListener.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
// Import event class
import mx.events.ValidationResultEvent;
private function handleValid(event:ValidationResultEvent):void {
if(event.type==ValidationResultEvent.VALID)
submitButton.enabled = true;
else
submitButton.enabled = false;
}
// Submit form is everything is valid.
private function submitForm():void {
// Handle submit.
}
]]>
</mx:Script>
<mx:ZipCodeValidator
source="{inputZip}" property="text"
valid="handleValid(event);"
invalid="handleValid(event);"/>
<mx:TextInput id="inputZip"/>
<mx:TextInput id="inputPn"/>
<mx:Button id="submitButton"
label="Submit"
enabled="false"
click="submitForm();"/>
</mx:Application>
文件上传验证validator例子:
http://www.adobe.com/devnet/flex/articles/custom_validator.html
是否相等validator例子:
http://blowingthroughlines.com/2009/02/18/uncategorized/flex-custom-validator-email-confirmation/