|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
RegEx help
Author: Patrick McElhaney
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261955
> ^(?=.*[A-Za-z])(?=.*[0-9])(?!.*[^A-Za-z0-9])(?!.*\s).{6,12}$
>
Hmm... I don't think this part is necessary:
"(?!.*[^A-Za-z0-9])(?!.*\s)" No one said anything about
non-alphanumeric characters being disallowed, did they?
If that's what you're going for we can simplify a bit.
^(?=.*[A-Za-z])(?=.*[0-9])[A-Za-z0-9]{6,12}$
Patrick
--
Patrick McElhaney
704.560.9117
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261935
NOW you got it :-) good job. I tried a couple times myself. Then gave up...
then I got annoyed and tried some more.... wash -> rinse -> repeat.... lol
.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
Sorry, can't get this outta my head now. Too interesting a challenge.
I believe this one will do it.
^(?=.*[A-Za-z])(?=.*[0-9])(?!.*[^A-Za-z0-9])(?!.*\s).{6,12}$
LOL, as was said originally, easier to break it up into two expressions
than worry about creating a monstrous pattern (as shown above).
Steve Brownlee
http://www.fusioncube.net
'11111a111111' fails
'aaaaa1aaaaaa' fails
'11111a' fails
'aaaaa1' fails
Actually... I guess everything I feed that one fails. Just go with Bens
original solution. It made it MUCH easier.
Author: Ben Nadel
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261934
Niiiiiiiice :D
Yeah, I know what you mean. I have gone back to this like three times
and couldn't figure it out. I have never used chained look aheads.
That's a nice little trick (or rather usage of the language). Freakin'
sweet.
.....................
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
Need ColdFusion Help?
www.bennadel.com/ask-ben/
Sorry, can't get this outta my head now. Too interesting a challenge.
I believe this one will do it.
^(?=.*[A-Za-z])(?=.*[0-9])(?!.*[^A-Za-z0-9])(?!.*\s).{6,12}$
LOL, as was said originally, easier to break it up into two expressions
than worry about creating a monstrous pattern (as shown above).
Steve Brownlee
http://www.fusioncube.net
Author: Steve Brownlee
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261932
Sorry, can't get this outta my head now. Too interesting a challenge.
I believe this one will do it.
^(?=.*[A-Za-z])(?=.*[0-9])(?!.*[^A-Za-z0-9])(?!.*\s).{6,12}$
LOL, as was said originally, easier to break it up into two expressions
than worry about creating a monstrous pattern (as shown above).
Steve Brownlee
http://www.fusioncube.net
'11111a111111' fails
'aaaaa1aaaaaa' fails
'11111a' fails
'aaaaa1' fails
Actually... I guess everything I feed that one fails. Just go with Bens
original solution. It made it MUCH easier.
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261925
'11111a111111' fails
'aaaaa1aaaaaa' fails
'11111a' fails
'aaaaa1' fails
Actually... I guess everything I feed that one fails. Just go with Bens
original solution. It made it MUCH easier.
.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
> What engine are you testing with? Patrick's pattern validates against
> all numeric, all alpha, and mixed against Perl 5, JDK 1.4 and JDK 1.5
> implmenetations.
He's saying "all numeric" isn't valid; there must be at least one letter.
If you want to require at least one number *and at least one letter*
this should work.
/^(?=.*\d)(?=.*[A-Za-z]).{6,12}$/
Patrick
--
Patrick McElhaney
704.560.9117
Author: Patrick McElhaney
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261923
> What engine are you testing with? Patrick's pattern validates against
> all numeric, all alpha, and mixed against Perl 5, JDK 1.4 and JDK 1.5
> implmenetations.
He's saying "all numeric" isn't valid; there must be at least one letter.
If you want to require at least one number *and at least one letter*
this should work.
/^(?=.*\d)(?=.*[A-Za-z]).{6,12}$/
Patrick
--
Patrick McElhaney
704.560.9117
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261920
All numeric and all alpha should fail according to the requirements of th
original post
.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
What engine are you testing with? Patrick's pattern validates against
all numeric, all alpha, and mixed against Perl 5, JDK 1.4 and JDK 1.5
implmenetations.
No it doesn't. Neither does yours. Patrick's was closer though.
The only thing I could find that it failed on was an all numeric string
6 to
12 characters long. Yours failed for that as well as a string of all
letters
6 to 12 characters long.
Where's Ben Doom? lol
Author: Steve Brownlee
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261913
What engine are you testing with? Patrick's pattern validates against
all numeric, all alpha, and mixed against Perl 5, JDK 1.4 and JDK 1.5
implmenetations.
No it doesn't. Neither does yours. Patrick's was closer though.
The only thing I could find that it failed on was an all numeric string
6 to
12 characters long. Yours failed for that as well as a string of all
letters
6 to 12 characters long.
Where's Ben Doom? lol
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261911
No it doesn't. Neither does yours. Patrick's was closer though.
The only thing I could find that it failed on was an all numeric string 6 to
12 characters long. Yours failed for that as well as a string of all letters
6 to 12 characters long.
Where's Ben Doom? lol
.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
Forget my attempt, Patrick's works perfectly.
You could try this...
\b[(\d+|\w+)]{6,12}\b
Author: Steve Brownlee
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261904
Forget my attempt, Patrick's works perfectly.
You could try this...
\b[(\d+|\w+)]{6,12}\b
Author: Steve Brownlee
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261899
You could try this...
\b[(\d+|\w+)]{6,12}\b
Hello all,
Im a bit rusty with regular expressions and I know this is an easy one
so im kicking myself for not having it that much more.
Im simply trying to ensure that a given string has between 6 and 12
characters and contains at least 1 numeric character.
Any help would be greatly appreciated!
-chris
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261809
That looks VERY similar to one I found and tried for this thread :-)
It didn?t work either. It was the same problem, '111111' validates but he
asked for letters and at least 1 number. I took that as meaning it has to
have at least 1 letter and at least 1 number.
.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
Can't resist the challenge. :-)
"^(?=.*\d).{6,12}$"
I'm not sure if this will actually work in CF.
Patrick
> You can also still do it in one cfset with Ben's 2 separate expressions...
>
> <cfset var = "abcdefg1" />
> <cfset newvar = refindnocase("[\w]{6,12}", var) AND refind("[0-9]+", var)
/>
----- Excess quoted text cut - see Original Post for more -----
Author: Patrick McElhaney
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261803
Can't resist the challenge. :-)
"^(?=.*\d).{6,12}$"
I'm not sure if this will actually work in CF.
Patrick
----- Excess quoted text cut - see Original Post for more -----
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261734
But I guess that?s what Ben did heh...
.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
I say break it up into two different test:
<cfif
REFind( "[\w]{6,12}", strText ) AND
REFind( "[0-9]+", strText )>
</cfif>
It keeps it much more simple and easy to read than a bigger, more
complex RegEx
......................
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
Need ColdFusion Help?
www.bennadel.com/ask-ben/
Hello all,
Im a bit rusty with regular expressions and I know this is an easy one
so im kicking myself for not having it that much more.
Im simply trying to ensure that a given string has between 6 and 12
characters and contains at least 1 numeric character.
Any help would be greatly appreciated!
-chris
_____
I've stopped 6,181 spam and fraud messages. You can too!
Free trial of spam and fraud protection at HYPERLINK
"http://www.cloudmark.com/sigs?rc=m874hl"www.cloudmark.com
HYPERLINK "http://www.cloudmark.com/sigs?rc=m874hl"
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.17/553 - Release Date:
11/27/2006
Author: Bobby Hartsfield
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261733
You can also still do it in one cfset with Ben's 2 separate expressions...
<cfset var = "abcdefg1" />
<cfset newvar = refindnocase("[\w]{6,12}", var) AND refind("[0-9]+", var)
/>
.:.:.:.:.:.:.:.:.:.:.:.
Bobby Hartsfield
http://acoderslife.com
I say break it up into two different test:
<cfif
REFind( "[\w]{6,12}", strText ) AND
REFind( "[0-9]+", strText )>
</cfif>
It keeps it much more simple and easy to read than a bigger, more
complex RegEx
......................
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
Need ColdFusion Help?
www.bennadel.com/ask-ben/
Hello all,
Im a bit rusty with regular expressions and I know this is an easy one
so im kicking myself for not having it that much more.
Im simply trying to ensure that a given string has between 6 and 12
characters and contains at least 1 numeric character.
Any help would be greatly appreciated!
-chris
_____
I've stopped 6,181 spam and fraud messages. You can too!
Free trial of spam and fraud protection at HYPERLINK
"http://www.cloudmark.com/sigs?rc=m874hl"www.cloudmark.com
HYPERLINK "http://www.cloudmark.com/sigs?rc=m874hl"
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.17/553 - Release Date:
11/27/2006
Author: Ben Nadel
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261716
I say break it up into two different test:
<cfif
REFind( "[\w]{6,12}", strText ) AND
REFind( "[0-9]+", strText )>
</cfif>
It keeps it much more simple and easy to read than a bigger, more
complex RegEx
.....................
Ben Nadel
Certified Advanced ColdFusion MX7 Developer
www.bennadel.com
Need ColdFusion Help?
www.bennadel.com/ask-ben/
Hello all,
Im a bit rusty with regular expressions and I know this is an easy one
so im kicking myself for not having it that much more.
Im simply trying to ensure that a given string has between 6 and 12
characters and contains at least 1 numeric character.
Any help would be greatly appreciated!
-chris
_____
I've stopped 6,181 spam and fraud messages. You can too!
Free trial of spam and fraud protection at HYPERLINK
"http://www.cloudmark.com/sigs?rc=m874hl"www.cloudmark.com
HYPERLINK "http://www.cloudmark.com/sigs?rc=m874hl"
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.17/553 - Release Date:
11/27/2006
Author: Chris Alvarado
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:49050#261703
Hello all,
Im a bit rusty with regular expressions and I know this is an easy one so im
kicking myself for not having it that much more.
Im simply trying to ensure that a given string has between 6 and 12 characters
and contains at least 1 numeric character.
Any help would be greatly appreciated!
-chris
_____
I've stopped 6,181 spam and fraud messages. You can too!
Free trial of spam and fraud protection at HYPERLINK "http://www.cloudmark.com/sigs?rc=m874hl"www.cloudmark.com
HYPERLINK "http://www.cloudmark.com/sigs?rc=m874hl"
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.17/553 - Release Date: 11/27/2006
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||