Reprinted from http://amberoracle.blog.163.com/blog/static/10598633820097262242474/
Step 1: Write the as class to inherit MX. validators. validator and import MX. validators. validationresult.
Value stores the content to be verified
The results are stored in the Results array. If verification is successful, the data is empty. If verification fails, the array contains the validationresult. object, which contains the failure information.
Package utils
{
Imp ort MX. validators. validator;// The validator class is for all flex VerificationProgram.
IMP Ort mx. validators. validationresult;
Public class addressvalidator extends validator
{
Private var results: array;
Public Function addressvalidator ()
{
Super ();
}
Protected override function dovalidation (value: Object): Array { // Protected method protect; dovalidation (value: Object): array; execute the verification logic of this verification program, this includes verifying whether missing values or null values cause verification errors defined by the value of the required attribute.
Results = [];
Results = super. dovalidation (value );
If (value! = NULL)
{
VaR pattern: Regexp = new Regexp ("\ D + \ x20 [A-Za-Z] + ");
If (value. Search (pattern) =-1 ){
Results. Push (New validationresult (true, null, "notaddress", "This is not a valid address "));
// Error Message
}
}
Return results; // If the returned string is null, it passes verification. If there is any content, it is the result of verification failure.
}
}
}
Step 2: import the flex Program
Xmlns: U = "utils .*"
Create validators
<U: addressvalidator id = "addressv" Source = "{billingaddress}" property = "text" required = "true"/>
Id validator name
Source verification Source
Property Verification source location property name
Required cannot be blank
Step 3: Import IMP in the flex Program Ort mx. Events. validationresultevent;
To determine the verification results.
Private var vaddressresult: validationresultevent = NULL;
Inspection:
Private function process (): void {
Vaddressresult = addressv. Validate (); // The validator performs the validate () method for verification. // Validate () method
// Public function validate (value: Object = NULL, suppressevents: Boolean = false): validationresultevent
// Perform the verification and (optional) notify the listener of the result.
If (vaddressresult. type = validationresultevent. valid) { // determine whether verification is successful
var E: objectdataevent = new objectdataevent ("billinginforeturn", checkoutinfo);
This. dispatchevent (E);
}< BR >}