|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
RegEx help
Hello all,Chris Alvarado 11/27/06 09:09 A I say break it up into two different test:Ben Nadel 11/27/06 09:33 A You can also still do it in one cfset with Ben's 2 separate expressions...Bobby Hartsfield 11/27/06 11:05 A Can't resist the challenge. :-)Patrick McElhaney 11/27/06 09:24 P That looks VERY similar to one I found and tried for this thread :-)Bobby Hartsfield 11/27/06 10:26 P But I guess that?s what Ben did heh...Bobby Hartsfield 11/27/06 11:07 A You could try this...Steve Brownlee 11/28/06 02:30 P Forget my attempt, Patrick's works perfectly.Steve Brownlee 11/28/06 02:48 P No it doesn't. Neither does yours. Patrick's was closer though.Bobby Hartsfield 11/28/06 03:21 P What engine are you testing with? Patrick's pattern validates againstSteve Brownlee 11/28/06 03:27 P All numeric and all alpha should fail according to the requirements of thBobby Hartsfield 11/28/06 04:02 P > What engine are you testing with? Patrick's pattern validates againstPatrick McElhaney 11/28/06 04:10 P '11111a111111' failsBobby Hartsfield 11/28/06 04:28 P Sorry, can't get this outta my head now. Too interesting a challenge.Steve Brownlee 11/28/06 05:20 P Niiiiiiiice :DBen Nadel 11/28/06 05:26 P NOW you got it :-) good job. I tried a couple times myself. Then gave up...Bobby Hartsfield 11/28/06 05:32 P > ^(?=.*[A-Za-z])(?=.*[0-9])(?!.*[^A-Za-z0-9])(?!.*\s).{6,12}$Patrick McElhaney 11/28/06 08:10 P 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 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 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 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 ----- 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 ----- 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 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 Forget my attempt, Patrick's works perfectly. You could try this... \b[(\d+|\w+)]{6,12}\b 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 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 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 > 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 '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 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. 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 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. > ^(?=.*[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
|
July 31, 2010
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||