Looking for a certain regexp
From: Robert TV (ducott_at_hotmail.com)
Date: 06/30/04
- Next message: Anno Siegel: "Re: error logs..."
- Previous message: Gunnar Hjalmarsson: "Re: HTTP::Request, trailing slash"
- Next in thread: Jürgen Exner: "Re: Looking for a certain regexp"
- Reply: Jürgen Exner: "Re: Looking for a certain regexp"
- Reply: Robert TV: "Re: Looking for a certain regexp"
- Reply: Purl Gurl: "Re: Looking for a certain regexp"
- Reply: Eric Schwartz: "Re: Looking for a certain regexp"
- Reply: Robert TV: "Re: Looking for a certain regexp"
- Reply: Sherm Pendley: "Re: Looking for a certain regexp"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Jun 2004 23:16:33 GMT
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
- Next message: Anno Siegel: "Re: error logs..."
- Previous message: Gunnar Hjalmarsson: "Re: HTTP::Request, trailing slash"
- Next in thread: Jürgen Exner: "Re: Looking for a certain regexp"
- Reply: Jürgen Exner: "Re: Looking for a certain regexp"
- Reply: Robert TV: "Re: Looking for a certain regexp"
- Reply: Purl Gurl: "Re: Looking for a certain regexp"
- Reply: Eric Schwartz: "Re: Looking for a certain regexp"
- Reply: Robert TV: "Re: Looking for a certain regexp"
- Reply: Sherm Pendley: "Re: Looking for a certain regexp"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|