R
Robert TV
Hi, has onyone ever created a regexp to match common credit card formulas? I
have been asked to "validate" some CC#'s we have on file. I do not know the
formulas by which credit cards are generated. All I know is Visa always
starts with 4, Mastercard with 5, and Amex with 3 I think. It would be nice
to have:
$cardtype = param('cardtype');
$cardnumber = param('cardnumber');
if ($cardtype eq "Visa") {
unless ($cardnumber =~ /some valid visa formula/) {
print "It's Good";
} else {
print "It's Bad";
}
}
And so forth. You can find e-commerce websites all over the place that do a
basic check but I don't know the formulas used. At the very least, I would
like to validate the first number as being 4,5,3 etc. and that the scalar is
at least 13 characters long. I do not know how to match just the very first
char of a scalar ... can some one help me with this? EG:
$cardtype = param('cardtype');
$cardnumber = param('cardnumber');
if ($cardtype eq "Visa") {
unless ($cardnumber =~ /first character is 4/ && $cardnumber =~ /at least
13 characters long/) {
print "It's Good";
} else {
print "It's Bad";
}
}
I am very new to writing regexp's and my present knowledge is limited to
validating characters used, not their positions. This was my best guess to
match 4 as first (untested):
unless ($cardnumber =~ /4.*/) { #does not match character length as 13
however
print "It's Good";
} else {
print "It's Bad";
}
Thank you all.
Robert
have been asked to "validate" some CC#'s we have on file. I do not know the
formulas by which credit cards are generated. All I know is Visa always
starts with 4, Mastercard with 5, and Amex with 3 I think. It would be nice
to have:
$cardtype = param('cardtype');
$cardnumber = param('cardnumber');
if ($cardtype eq "Visa") {
unless ($cardnumber =~ /some valid visa formula/) {
print "It's Good";
} else {
print "It's Bad";
}
}
And so forth. You can find e-commerce websites all over the place that do a
basic check but I don't know the formulas used. At the very least, I would
like to validate the first number as being 4,5,3 etc. and that the scalar is
at least 13 characters long. I do not know how to match just the very first
char of a scalar ... can some one help me with this? EG:
$cardtype = param('cardtype');
$cardnumber = param('cardnumber');
if ($cardtype eq "Visa") {
unless ($cardnumber =~ /first character is 4/ && $cardnumber =~ /at least
13 characters long/) {
print "It's Good";
} else {
print "It's Bad";
}
}
I am very new to writing regexp's and my present knowledge is limited to
validating characters used, not their positions. This was my best guess to
match 4 as first (untested):
unless ($cardnumber =~ /4.*/) { #does not match character length as 13
however
print "It's Good";
} else {
print "It's Bad";
}
Thank you all.
Robert