Skip to content

Instantly share code, notes, and snippets.

@andreybutov
Created August 11, 2018 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreybutov/ca56b328ad9f58f53af657aa5ca136cc to your computer and use it in GitHub Desktop.
Save andreybutov/ca56b328ad9f58f53af657aa5ca136cc to your computer and use it in GitHub Desktop.
Validating BlackBerry PIN codes in Perl
#
# Validating a BlackBerry PIN in Perl.
#
# Andrey Butov ( andreybutov.com )
#
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment