House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

RegEx help

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Chris Alvarado
11/27/2006 09:09 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Nadel
11/27/2006 09:33 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bobby Hartsfield
11/27/2006 11:05 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick McElhaney
11/27/2006 09:24 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bobby Hartsfield
11/27/2006 10:26 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bobby Hartsfield
11/27/2006 11:07 AM

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

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Steve Brownlee
11/28/2006 02:30 PM

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

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Steve Brownlee
11/28/2006 02:48 PM

Forget my attempt, Patrick's works perfectly. You could try this...   \b[(\d+|\w+)]{6,12}\b

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bobby Hartsfield
11/28/2006 03:21 PM

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

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Steve Brownlee
11/28/2006 03:27 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bobby Hartsfield
11/28/2006 04:02 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick McElhaney
11/28/2006 04:10 PM

> 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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bobby Hartsfield
11/28/2006 04:28 PM

'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

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Steve Brownlee
11/28/2006 05:20 PM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ben Nadel
11/28/2006 05:26 PM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Bobby Hartsfield
11/28/2006 05:32 PM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Patrick McElhaney
11/28/2006 08:10 PM

>         ^(?=.*[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


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

July 31, 2010

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
         1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31