Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Quicky: Regex for credit card expiry date 'mm/yy'

926 views
Skip to first unread message

Scott Dellar

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
Hey there all,
just a small issue with regular expressions
I am attempting to detect valid expiry dates for a credit card
The system is made up so don't get too serious
All I want is to detect strings of the form 'mm/yy'
At the moment, I have something like:
/^[1-12].[0-99]$/
I have the dot there because I am not sure how to detect a forward slash -
that is the special character which makes it a matching operator.
Any help = good,
Thanks
Scott


xerx...@my-deja.com

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
i would do this

/(\d){2}\/(\d){2}/

this will capture mm into $1 and yy into $2;
note the baclslash in front of the forward slash. this escapes any
specials charcters. allowing u to use them literally.
alternatively
m!(\d){2}/(\d){2}!
u can use different delimiters wich make / literal.


Sent via Deja.com http://www.deja.com/
Before you buy.

Joris Hilhorst

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to

er... how about: m#[1-12]/[0-99]$# ? (or use m( .... ) or m" ...
" )
allthough I am not too sure about the 1-12 stuff.
the m operator lets you choose your own boundary character.

alternatively: use /^[1-12]\/[0-99]$/ (so use the \ to escape the / )
regards,
Joris Hilhorst

xerx...@my-deja.com

unread,
Oct 24, 2000, 3:00:00 AM10/24/00
to
oh yeah i meant to say '\d' is short for any digit.
note the lower case 'd', upper case \D is any non digit.


In article <8t3n6b$pbg$1...@nnrp1.deja.com>,

0 new messages