tags:

views:

47

answers:

2

Hi, How can the cfinput tag be set to validate the minimum input length? (E.g. To a minimum of 8 characters long)

Currently have:

<cfinput type="password" name="password " label="Password" required="yes" message="Please Enter Your Password"> 

Any help will be appreciated.

+2  A: 
       <script>
        function validatePassword(pass) {   
            //custom javascript code
            alert(pass.length);
        }
        </script>

        <cfform name="registration">
        <cfinput id="password" 
                type="password" 
                name="password" 
                label="Password" 
                required="yes" 
                message="Please Enter Your Password" 
                onkeyup="javascript:validatePassword(this.value);" />
        </cfform>

Or something like that... Just disable submit button until you get upto 8 chars, and/or display some red/green info etc...

zarko.susnjar
+4  A: 

You can also use Regular Expression which will validate for a pattern with length between 8 and 16, allowing upper and lower case letters, numbers, periods, and underscores.

<cfinput type="password" name="password " label="Password" required="yes" validate="regex" pattern="^[a-zA-Z0-9._]{8,16}$" message="Please Enter Your Password">
Pragnesh Vaghela
label="Password" usually doesn't do anything... unless you're using XForm/FlashForm with CFFORM... :S
Henry
Thanks for the tip Henry
Nich
The script works well, Thank you.
Nich
Just want to find out, how can this be done as a server side validation and not client side? For if the client disables javascript, then the validations wont work, thus server side is needed.
Nich
Nich ideally you would want to have both client and server side validation.
Pragnesh Vaghela