在文本字段上进行perl验证

时间:2011-08-12 20:35:18

标签: php perl

我有以下perl代码:

my $pin = <get PIN from submitted web page data>
return “Error” if !defined($pin);
$pin = &trimAndUpper($pin);
# Test for length validity.
return “Error” unless length($pin) == 8;
# Test for hex validity.
return “Error” unless ($pin =~ /^[[:xdigit:]]+$/);
# Good PIN at this point.
sub trimAndUpper {
  my ($str) = @_;
  $str =~ s/^\s+//; # left trim
  $str =~ s/\s+$//; # right trim
  $str =~ tr/a-z/A-Z/; # to upper
  return $str;
}

我无法将其转换为PHP,有人可以帮忙吗?

1 个答案:

答案 0 :(得分:5)

我会与你的努力相匹配: http://www.cs.wcupa.edu/~rkline/perl2php/