in reply to Checking name convention

You can use a regular expression to look for the pattern, and an until loop to keep prompting the user until their input matches your desired pattern:
my $os_user = '&'; #stop warnings from yelling at you print "OS username:"; until ($os_user =~ /^[A-Za-z]{3}\d{3}$/) { chomp($os_user = <>); }

Replies are listed 'Best First'.
Re^2: Checking name convention
by AnomalousMonk (Archbishop) on Feb 24, 2015 at 19:15 UTC

    Because no  $ end-of-string anchor is used, the  /^[A-Za-z]{3}\d{3}/ match may allow something improper:

    c:\@Work\Perl\monks>perl -wMstrict -le "my $os_user = 'foo9876543210'; $os_user =~ /^[A-Za-z]{3}\d{3}/ or die qq{bad user name: '$os_user'}; print qq{'$os_user' is ok by me!}; " 'foo9876543210' is ok by me!
    See above for a variation that avoids this problem. See also perlre, perlrequick, and perlretut.


    Give a man a fish:  <%-(-(-(-<

      Woops, you're right. Updated it with the requisite anchor.