"Robert TV" <> writes:
> Hi, has onyone ever created a regexp to match common credit card formulas?
If you were to search for "Credit Card" on
http://search.cpan.org/
you'd find Business::CreditCard which claims to
Validate/generate credit card checksums/names
You know, it's kinda rude to ask other people to search for you, when
you can just do the same thing yourself.
> I have been asked to "validate" some CC#'s we have on file.
Do you know what "validate" means? Are you supposed to make sure
they're real credit card numbers, or just that they might be?
Business::CreditCard doesn't really validate cards; it just makes sure
that the credit card number is vaguely plausible.
> I am very new to writing regexp's and my present knowledge is limited to
> validating characters used, not their positions.
You should read 'perldoc perlretut', then. 'perldoc perlrequick' if
you're in a hurry.
> This was my best guess to
> match 4 as first (untested):
Why? You can test it yourself, easily.
> unless ($cardnumber =~ /4.*/) { #does not match character length as 13
That will match a string with a literal '4' in it anywhere.
> however
That will cause a syntax error.
> print "It's Good";
>
> } else {
> print "It's Bad";
> }
Sounds like you've got an idea that regexes can do anything; they can
do a lot, but they're not ideal for everything. Also, sometimes it's
clearer to express yourself not using a regex. For instance, if what
you're concerned with is to find the length of a string, use the
length() function ('perldoc -f length' to find out more).
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.