We help IT Professionals succeed at work.

string max length regex help

In the language ColdFusion I have an expression where I am validating Upper, Lower, Number, Special, Min Length, but I can't get Max Length to work.
I am adding a number - 10 for ex - after the 6, in the expression, but to no avail.
Is this the correct syntax?
Any ideas?

And yes - I want it in the same expression not by testing len(string) ...

Watch Question

Most Valuable Expert 2014
Top Expert 2015

I had tried that - got it from Googling - and it doesn't work ...
Most Valuable Expert 2014
Top Expert 2015

What does it match that it should not, or what does it not match that it should?
the max length - that's what this question is ...
You can check your regular expression syntax using the following online tool:

Typically the following should work for dealing with length:
Exact Length - Consist of exactly ten letters

Length Range - Consist of a minimum of three letters and a maximum of ten

Minimum Length - Consist of at least three letters
hey guys
I did find online examples but as I said I can't get the max length to work.
Any ideas on why my regex isn't working as intended?
The language is CF

Which CF tag or function are you using with the regex? Do you have a code snippet to share?
<cfset regex="(?=.*[A-Z])(?=.*[~!@##$%^&*_+=?-])(?=.*[0-9])(?=.*[a-z]).{6,}">
REFind(regex, form.password)

It seems as if it is working as intended except for max length which i have attempted like so:
<cfset regex="(?=.*[A-Z])(?=.*[~!@##$%^&*_+=?-])(?=.*[0-9])(?=.*[a-z]).{6,10}">
<cfset regex="(?=.*[A-Z])(?=.*[~!@##$%^&*_+=?-])(?=.*[0-9])(?=.*[a-z]).{6,10}$">

Try the following regex. It appears to work with my four test cases.

<cfparam name="form.password1" default="L_a~l5"> <!--- Meets min length --->
<cfparam name="form.password2" default="L_a~lor16@A"> <!--- Too long --->
<cfparam name="form.password3" default="L_a"> <!--- Too short --->
<cfparam name="form.password4" default="L*a4YtG6%h"> <!--- Meets max length --->

<p><strong>Test 1 - Meets min length</strong></p>
<cfset regex="^((?=.*[A-Z])(?=.*[~!@##$%^&*_+=?-])(?=.*[0-9])(?=.*[a-z]))(.{6,10})$">
<p><cfoutput>#REFind(regex, form.password1)#</cfoutput> </p>

<p><strong>Test 2 - Too long</strong></p>
<cfset regex="^((?=.*[A-Z])(?=.*[~!@##$%^&*_+=?-])(?=.*[0-9])(?=.*[a-z]))(.{6,10})$">
<p><cfoutput>#REFind(regex, form.password2)#</cfoutput> </p>

<p><strong>Test 3 - Too short</strong></p>
<cfset regex="^((?=.*[A-Z])(?=.*[~!@##$%^&*_+=?-])(?=.*[0-9])(?=.*[a-z]))(.{6,10})$">
<p><cfoutput>#REFind(regex, form.password3)#</cfoutput> </p>

<p><strong>Test 4 - Meets max length</strong></p>
<cfset regex="^((?=.*[A-Z])(?=.*[~!@##$%^&*_+=?-])(?=.*[0-9])(?=.*[a-z]))(.{6,10})$">
<p><cfoutput>#REFind(regex, form.password4)#</cfoutput> </p>

Open in new window

This appears to work perfectly - Thanks!