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.
(?=.*[A-Z])(?=.*[~!@##$%^&*_+=?])(?=.*[0-9])(?=.*[a-z]).{6,}
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) ...

Thanks
LVL 25
dgrafxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
.{6,10}$
0
dgrafxAuthor Commented:
I had tried that - got it from Googling - and it doesn't work ...
0
ozoCommented:
What does it match that it should not, or what does it not match that it should?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

dgrafxAuthor Commented:
the max length - that's what this question is ...
0
LajuanTaylorCommented:
You can check your regular expression syntax using the following online tool:
https://regex101.com/

Typically the following should work for dealing with length:
Exact Length - Consist of exactly ten letters
/^[a-zA-Z]{10}$/

Length Range - Consist of a minimum of three letters and a maximum of ten
/^[a-zA-Z]{3,10}$/

Minimum Length - Consist of at least three letters
/^[a-zA-Z]{3,}$/
0
dgrafxAuthor Commented:
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

Thanks
0
LajuanTaylorCommented:
Which CF tag or function are you using with the regex? Do you have a code snippet to share?
0
dgrafxAuthor Commented:
<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}">
also
<cfset regex="(?=.*[A-Z])(?=.*[~!@##$%^&*_+=?-])(?=.*[0-9])(?=.*[a-z]).{6,10}$">

Thanks
0
LajuanTaylorCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgrafxAuthor Commented:
This appears to work perfectly - Thanks!
0
dgrafxAuthor Commented:
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.