Hi I’m trying to setup a RegexpValidator that only accepts a string of alphanumeric characters between 6-30 characters long and requires one number. I’m new to Regular Expressions and everything I’ve tried seems to keep returning an invalid ValidationRsultEvent. Here’s a chunk of code:
<mx:RegExpValidator id="regexValidator" source="{passwordInput}" property="text"
triggerEvent="" valid="onPasswordValidate(event)" invalid="onPasswordValidate(event)" />
private function validateRegister():void
{
regexValidator.expression = "^(?=.*(\d|\W)).{6,30}$";
regexValidator.validate();
}
I’m not sure what would be causing the Validation error, but as far as your regular expression goes, to match alphanumeric strings with at least one number try
^(?=.*\d)\w{6,30}$If you want to only match letters and numbers, instead of
\wyou can use[0-9a-zA-Z].Your current regular expression
^(?=.*(\d|\W)).{6,30}$is matching any string that contains at least one character other than[a-zA-Z_](\d|\Wmatches a digit, or “non-word” character), that is between 6 and 30 characters long, which does not necessarily meet the requirements you specified.