Created
August 11, 2018 13:28
-
-
Save andreybutov/ca56b328ad9f58f53af657aa5ca136cc to your computer and use it in GitHub Desktop.
Validating BlackBerry PIN codes in Perl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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