2 Replies Latest reply on Feb 11, 2008 9:11 AM by Gregory Lafrance

    Password StringValidator

    KomputerMan.com Level 1
      Hello all you fellow Flexers out there

      I want to use the StringValidator, or some bit of action script I suppose, to ensure that my end users has a password of 6 chars with at least one special character and at least one number.

      I already have two password boxes and have the checks to ensure that the password is the same in both boxes. Now all I need to do is to validate the length and check for the required special character and number. Any ideas???

      Thanks in advance!!!

      Have an Ordinary Day...
      KomputerMan ~|:-)
        • 1. Re: Password StringValidator
          dimival Level 1
          StringValidator has a minLength property which you can use to validate the length. For the special character you can use a regular expression to verify it.
          • 2. Re: Password StringValidator
            Gregory Lafrance Level 6
            The following code is not at all an elegant solution, but it uses regular expressions, and may get you started:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">
            <mx:Script>
            <![CDATA[
            public var digit:RegExp = /.*\d.*/;
            public var special:RegExp = /.*\W|_.*/;

            public function validatePassword():Boolean {
            var result:Boolean = false;
            if( (txtInput.length != 6) ||
            (!digit.test(txtInput.text)) ||
            (!special.test(txtInput.text)) ){
            return false;
            } else {
            return true;
            }
            }
            ]]>
            </mx:Script>
            <mx:TextInput id="txtInput"/>
            <mx:Button label="Validate Password" click="mx.controls.Alert.show(String(validatePassword()))"/>
            </mx:Application>