So I'm a perl noob, trying to decrypt some scary code at work. Here's whats current used for usernave validation:
# check username and password
foreach my $field (qw(order_username order_password)) {
next if $in{$field} =~ /\S+/;
($pf = $field) =~ s/^order_//;
$pf =~ s/\b(\w+)/\u$1\E/;
push(@errors, "The $pf field is missing or invalid.");
push(@todo, $field);
}
I've been search the web for a bit know trying to find out what "s/\b(\w+)/\u$1\E/" entails as far as validating.
What I need is for order_username validation to check for everthing it's currently looking for as well as set a restriction on the field to be uppercase only. If the user enters lower case it'll push the errors as normal
The order_password can be either upper or lower case. So I figure I'll need to break foreach into just a for order_username and another for order_password.
Can someone either point in the right direction or just bust me the solution?
Thank you in advance,
Justin S.
this line:
$pf =~ s/\b(\w+)/\u$1\E/;
just isn't correct, it would have to be with an uppercase 'U' for the \E operator to work:
$pf =~ s/\b(\w+)/\U$1\E/;
but since there are no \b (word boundaries) in the string it would probably just be better to use the 'uc' operator to change the string to all uppercase:
$pf = uc $pf;
but you still have to use a condition to check for $pf and push it into the @error array if necessary. But I am not sure what condition or conditions would cause that except if there in no $pf defined:
push(@errors, "The $pf field is missing or invalid.") if!$pf;
Glad to hear you have confidence in perl, but this line:
push(@errors, "The $pf field is missing or invalid.");
will always push $pf (and the message) into the @error array. Maybe that is what you want, but I'm doubting that.