I need to determine if this variable has at least one number and at least one character.

I assume you mean "and at least one letter." It'll have one character if its length is greater than 0.

fail() unless $password =~ /\d/; fail() unless $password =~ /[A-Za-z]/;

By the way, that regular expression is a bit of a mess. First, there seems to have been a transcription error because you never close your character class. Ignoring that though, there's just no reason to escape all of those characters and doing so just makes it difficult to read.

$password =~ /([-\\\/!*+@\s\w$.]/; # This is fine.

Any thoughts would be greatly appreciated.

I'm not a big fan of restricting passwords. That said, I know education isn't always an option. You can usually be sure, though, that if you require that a password has one letter and one number, 70% are going to choose a password of all letters and slap a number on the end. Another 20% will put the number first. So, the real effect, with such simple rules, is actually to reduce the work that a cracker would have to do if he got ahold of your encrypted passwords. You might be better off if you insist that one character other than the first or the last is a non-letter.

fail() unless $password =~ /^.+[^A-Za-z]./;

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: problems with regular expressions by sauoq
in thread problems with regular expressions 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.