Thanks - I tried that out but the problem is the Regex matches the
value that I don't want. In other words I need the opposite of the
matched expression to trigger a valid result, and the matched
expression to be invalid.
Anyways, after much canoodling I just overrode the Validator class.
Perhaps this will help someone else -
package classes
{
import mx.validators.ValidationResult;
import mx.validators.Validator;
public class CustomStringValidator extends Validator {
// Define Array for the return value of doValidation().
private var results:Array;
// Define the string that is not allowed and will trigger the
Validation error.
private var _stringNotAllowed:String;
private var _stringErrorMessage:String;
public function get stringNotAllowed():String{
return this._stringNotAllowed;
}
public function set stringNotAllowed(s:String):void{
_stringNotAllowed = s;
}
public function get stringErrorMessage():String{
return this._stringErrorMessage;
}
public function set stringErrorMessage(s:String):void{
_stringErrorMessage = s;
}
// Constructor.
public function CustomStringValidator() {
// Call base class constructor.
super();
}
// Define the doValidation() method.
override protected function doValidation(value:Object):Array {
// Clear results Array.
results = [];
// Call base class doValidation().
results = super.doValidation(value);
// Return if there are errors.
if (results.length > 0)
return results;
if(String(value) == _stringNotAllowed){
results.push(new
ValidationResult(true,null,"notAllowed",_stringErrorMessage));
return results;
}
return results;
}
}
}
In mxml, I declare the component as follows:
<comp:CustomStringValidator source="{myTextInput}" property="text"
stringNotAllowed="[Enter your name]" stringErrorMessage="Please enter
a valid name." />
--- In [email protected], "Ryan Gravener" <[EMAIL PROTECTED]> wrote:
>
> I suppose you would need to use the regular expression validator.
>
> Ryan Gravener
> http://twitter.com/ryangravener
>
>
> On Thu, Oct 2, 2008 at 12:46 PM, djohnson29 <[EMAIL PROTECTED]> wrote:
>
> > Does anyone know how to trigger a validator on a TextInput based
on a
> > certain string value?
> >
> > I have a regular TextInput with a regular Validator attached to it
> > (required Validation). I would like to also trigger this Validator so
> > that the red outline and tooltip displays when there is a particular
> > value in the text property.
> >
> > So if the TextInput is empty, then the required validation kicks in,
> > and if the text property contains for example, "foo", then then the
> > Validator fires as well.
> >
> > Is there a quick and easy way to do this without overridding the
> > Validator?
> >
> >
> >
>