`

FLEX : Validator 验证

    博客分类:
  • FLEX
阅读更多
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/
分享到:
评论

相关推荐

    Flex from_validator_表单验证

    2. 动态验证:在用户输入时即时进行验证,可以立即反馈错误,提高用户体验。 四、`from_validator`使用示例 以下是一个简单的使用`from_validator`进行表单验证的例子: ```xml &lt;!-- MXML 示例 --&gt; &lt;s:Form id=...

    flex form 验证(转)

    在Flex开发中,表单验证是一项关键任务,它确保用户输入的数据符合预设的规则,保证数据质量和系统安全。本文将深入探讨“flex form 验证”这一主题,结合给出的文件名,我们来详细讲解Flex中表单验证的相关知识点。...

    flex 内置验证器

    Flex 内置验证器是 Flex 框架中用于确保用户输入数据有效性的工具,它们提供了多种验证方式,包括实时验证、提交值验证、通过性验证和脚本式验证。这些验证器帮助开发者轻松地检查用户输入,确保数据格式正确且符合...

    Flex实现非空验证小例子

    在Flex中,我们可以使用Validator类来创建自定义验证器。首先,你需要创建一个继承自mx.validators.Validator的子类,覆盖validate()方法。在这个方法中,你可以添加你的验证逻辑,比如检查字段是否为空。如果字段为...

    构建Flex自动验证框架

    1. **验证组件**:Flex提供了多种内置验证组件,如Validator,它可以检查用户的输入是否符合预设规则,例如邮箱格式、数字范围等。开发者可以通过自定义验证规则扩展这些组件。 2. **事件驱动**:Flex验证过程通常...

    flex 表单数据合法性验证

    Flex允许在不同的时间点进行验证:实时验证(live validation)会在用户输入时立即执行,提交验证(commit validation)只在用户提交表单时执行。这可以通过设置Validator的validateOnCommit属性来控制。 6. **组...

    flex自动验证组建(插件)

    这些验证组件是基于Adobe Flex框架的Validator功能,能够为表单字段提供实时或提交时的验证,提高用户体验并减少服务器端的压力。 Flex验证组件的核心在于`Validator`类,它允许开发者定义验证规则,并在用户输入...

    Flex基础培训-5-[数据验证

    1. 服务端数据验证:当表单提交到服务器后,服务器端程序对数据进行验证。这种方式安全度高,但增加了服务器的负担和用户等待时间。 2. 客户端数据验证:在数据发送到服务器之前,先在客户端进行验证。这种方式可以...

    flex----组件---数据验证类

    数据验证在Flex中通常涉及到两个主要的类:Validator和Formatters。Validator类用于检查用户输入是否符合预设的验证规则,如非空、数字范围、邮箱格式等。这些验证规则可以通过创建Validator实例并设置其属性来实现...

    Flex数据显示与数据验证

    在Flex中,可以通过内置的验证器类来实现这一目标,这些验证器包括但不限于`CreditCardValidator`、`CurrencyValidator`、`DateValidator`和`EmailValidator`等。 #### 验证器的使用方式 验证器通常被定义在组件的...

    Java+flex使用dom4j读写xml

    使用到了验证控件Validator;使用了CSS样式对Alert对话框进行了修饰;使用了样式对Accordion的Canvas上的lable字体做了修饰。 总结:对Flex和Java对象之间的转换还要进一步的研究,认识到Flex中样式的重要性。Flex的...

    validate校验正则表达式验证

    在Flex中,我们可以使用`Validator`类结合正则表达式进行数据验证。例如: ```actionscript var emailValidator:Validator = new Validator(); emailValidator.source = emailInput; emailValidator.property = ...

    Flex UI组件使用全集

    - **CreditCardValidator**: 验证信用卡号码的有效性。 - **CurrencyValidator**: 验证货币数值的有效性。 - **DataValidator**: 验证日期格式。 - **EmailValidator**: 验证电子邮件地址的有效性。 - **...

    (十五)Flex4_格式化与校验器

    Flex4提供了Validator类,开发者可以通过继承这个基类来创建自定义的验证规则。内置的验证器包括StringValidator(用于检查字符串长度或格式)、NumberValidator(检查数值范围)以及DateValidator(验证日期格式)...

    郑岩峰,幻想Flex3,源代码6

    通过Validator类,开发者可以轻松地添加验证逻辑到表单组件上,提高用户体验并减少错误。 在Flex3中,你可以使用预定义的验证控件如NumberValidator、EmailValidator等,或者自定义验证规则。这些控件通常与Form或...

    flex-带checkbox的datagrid

    Flex提供了验证框架,可以通过Validator类实现。同时,当出现错误时,应使用错误提示和错误对象来通知用户。 通过以上知识点的应用,你可以创建一个功能完善的、带有复选框的Flex Datagrid,提供给用户高效、直观的...

    Flex入门教程[汇编].pdf

    5. 实现数据绑定和验证,包括使用BindingUtils类、Validator类和Form类等。 6. 使用Flex Builder开发工具,包括创建新项目、设计用户界面、编写代码和调试应用程序等。 此外,本教程还涵盖了一些高级话题,例如: ...

    Wrox.Professional.Adobe.Flex.2.May.2007

    #### 第15章 - Custom Formatter, Validator, and Effect Components(自定义格式器、验证器和效果组件) 除了UI组件外,Flex还支持创建自定义的格式器、验证器和效果组件,用于数据格式化、输入验证和动画效果。本...

    flex3+component组件.pdf

    Validator用于验证输入数据的有效性,如CreditCardValidator(信用卡验证器)、CurrencyValidator(货币验证器)、EmailValidator(电子邮件验证器)等。Formatter则用于格式化数据,例如CurrencyFormatter(货币...

Global site tag (gtag.js) - Google Analytics