Sorry for the slow reply, $work rather got in the way. Yes, it can be adapted quite easily:-

use strict; use warnings; use 5.014; use re qw{ eval }; my $max = shift || 3; my $ascPatt = q{(?x) ( \d ) (??{ join q{}, map { $1 + $_ } 1 .. $max }) }; my $descPatt = q{(?x) ( \d ) (??{ join q{}, map { $1 - $_ } 1 .. $max }) }; my @passwords = qw{ 1234 1243 4321 298761 4562 4568 4578 123 12 1 01234 01243 04321 0298761 04562 04568 04578 0123 012 01 a1234 1a234 12a34 123a4 1234a a1b2c3 a12b34c56 a1b2c3d a12b34c56d a123b45c6 a12b345c6 a123b45c6d a12b345c6d 1a2 1ab2 12ab34 12abc34def 12abc34def567 abc ab12c 2345 234y 01234 2356 }; say qq{$_ - }, checkConsec( $_ ) ? q{too many consecutive digits} : q{pass} for @passwords; sub checkConsec { my $pw = shift; return 1 if $pw =~ m{$ascPatt}; return 1 if $pw =~ m{$descPatt}; return 0; }

Three runs, the first using the default of no more than three consecutive digits, then four and two.

johngg@shiraz:~/perl/Monks > ./spw1148625 1234 - too many consecutive digits 1243 - pass 4321 - too many consecutive digits 298761 - too many consecutive digits 4562 - pass 4568 - pass 4578 - pass 123 - pass 12 - pass 1 - pass 01234 - too many consecutive digits 01243 - pass 04321 - too many consecutive digits 0298761 - too many consecutive digits 04562 - pass 04568 - pass 04578 - pass 0123 - too many consecutive digits 012 - pass 01 - pass a1234 - too many consecutive digits 1a234 - pass 12a34 - pass 123a4 - pass 1234a - too many consecutive digits a1b2c3 - pass a12b34c56 - pass a1b2c3d - pass a12b34c56d - pass a123b45c6 - pass a12b345c6 - pass a123b45c6d - pass a12b345c6d - pass 1a2 - pass 1ab2 - pass 12ab34 - pass 12abc34def - pass 12abc34def567 - pass abc - pass ab12c - pass 2345 - too many consecutive digits 234y - pass 01234 - too many consecutive digits 2356 - pass johngg@shiraz:~/perl/Monks > ./spw1148625 4 1234 - pass 1243 - pass 4321 - pass 298761 - pass 4562 - pass 4568 - pass 4578 - pass 123 - pass 12 - pass 1 - pass 01234 - too many consecutive digits 01243 - pass 04321 - pass 0298761 - pass 04562 - pass 04568 - pass 04578 - pass 0123 - pass 012 - pass 01 - pass a1234 - pass 1a234 - pass 12a34 - pass 123a4 - pass 1234a - pass a1b2c3 - pass a12b34c56 - pass a1b2c3d - pass a12b34c56d - pass a123b45c6 - pass a12b345c6 - pass a123b45c6d - pass a12b345c6d - pass 1a2 - pass 1ab2 - pass 12ab34 - pass 12abc34def - pass 12abc34def567 - pass abc - pass ab12c - pass 2345 - pass 234y - pass 01234 - too many consecutive digits 2356 - pass johngg@shiraz:~/perl/Monks > ./spw1148625 2 1234 - too many consecutive digits 1243 - pass 4321 - too many consecutive digits 298761 - too many consecutive digits 4562 - too many consecutive digits 4568 - too many consecutive digits 4578 - pass 123 - too many consecutive digits 12 - pass 1 - pass 01234 - too many consecutive digits 01243 - too many consecutive digits 04321 - too many consecutive digits 0298761 - too many consecutive digits 04562 - too many consecutive digits 04568 - too many consecutive digits 04578 - pass 0123 - too many consecutive digits 012 - too many consecutive digits 01 - pass a1234 - too many consecutive digits 1a234 - too many consecutive digits 12a34 - pass 123a4 - too many consecutive digits 1234a - too many consecutive digits a1b2c3 - pass a12b34c56 - pass a1b2c3d - pass a12b34c56d - pass a123b45c6 - too many consecutive digits a12b345c6 - too many consecutive digits a123b45c6d - too many consecutive digits a12b345c6d - too many consecutive digits 1a2 - pass 1ab2 - pass 12ab34 - pass 12abc34def - pass 12abc34def567 - too many consecutive digits abc - pass ab12c - pass 2345 - too many consecutive digits 234y - too many consecutive digits 01234 - too many consecutive digits 2356 - pass johngg@shiraz:~/perl/Monks >

I hope this is helpful.

Cheers,

JohnGG


In reply to Re^3: Check a string for consecutive digits by johngg
in thread Check a string for consecutive digits by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.