Of course merlyn has a very important point -- the more different characters you allow in your password field, the harder to guess the password.

To answer your question, though, you'll need something like this:

if( $password =~ m/^[DesiredCharactersHere]+$/ ) { it's "reasonable" } else { it's not reasonable }

It's a common saying that Perl gives you more than enough rope to hang yourself. Something similar can be said of the community too. We're not big on refusing to tell people some bit of knowledge. It's just that as we hand you that rope (and even telling you how to tie the knots), we're usually telling you why it isn't a good idea.

Update: Thanks to merlyn for catching the security hole. I've left the code with the bug in place so his post continues to make sense.

One thing I think is important to note about most of the replies that hasn't been explicitly mentioned is notice that almost all the code examples test for DesiredCharacters, not UndesiredCharacters. This is a best-practices approach to making sure you only get _exactly_ what you want in your password field, with no chances of forgetting to exclude anything undesired. That was my intention as well, but I seem to have let one (\n) slip in anyways.


In reply to Re: Yet another REGEXP Question by AidanLee
in thread Yet another REGEXP Question by fastkeys

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.