- if ($name !~ /^[a-z0-9_][a-z0-9_\-]*$/ || $name eq "a-z0-9_-") {
- warn "Wrong username. " .
- "Please use only lowercase characters or digits\a\n";
+ if ($name eq $usernameregexp) { # user/admin just pressed <Return>
+ warn "Please enter a username\a\n";
+ return 0;
+ } elsif (length($name) > 16) {
+ warn "Username is longer than 16 characters.\a\n";
+ return 0;
+ } elsif ($name =~ /[:\n]/) {
+ warn "Username cannot contain colon or newline characters.\a\n";
+ return 0;
+ } elsif ($name !~ /$usernameregexp/) {
+ if ($usernameregexp eq $defaultusernameregexp) {
+ warn "Illegal username.\n" .
+ "Please use only lowercase Roman, decimal, underscore, " .
+ "or hyphen characters.\n" .
+ "Additionally, a username should not start with a hyphen.\a\n";
+ } else {
+ warn "Username doesn't match the regexp /$usernameregexp/\a\n";
+ }