basically it's:
^(<regex>)?$
To test for "empty OR regex", as Tim suggested, because ? means 0 or 1 instances of something.
Paul
Douglas Humphris wrote:
Thanks Paul,
Actually it wasn't so much the date format that I was having problems with, it was the empty string bit - how do you get a reg exp to return true for a valid mm/yy OR an empty string?
I've not refined my reg exp to what Tim suggested: "^([01][0-9]/[0-9]{2})?$" and am just testing for the length of the string separately.
Douglas
-----Original Message-----
From: Paul Johnston [mailto:[EMAIL PROTECTED] Sent: 29 April 2004 10:58
To: [EMAIL PROTECTED]
Subject: Re: [ cf-dev ] Reg Exp
Douglas,
Douglas Humphris wrote:
<cfset reCardDate = "^(([0-1]{1,1})([0-9]{1,1})/([0-9]{2,2})){0,1}$"/>
<cfset cardStartDate = "" />I'm sure this has been answered by others, but just to add, this is how I would do it:
<cfoutput>#REFind(reCardDate,cardStartDate)#</cfoutput>
Basically, I want it to return true for the empty string, or for a valid mm/yy date format.
to get the month in mm format, that is going to be anything from 01 to 12 (not allowing 13-19):
(0[1-9]|1[0-2])
then there's a slash
/
then there's the year formatted correctly
0[0-9]
That year will give you anything from 00 to 09. This can be amended to just allow years up until now, or to allow only a certain subset of years, eg to allow any year from 1980 onwards up until this year:
((8|9)[0-9]|0[0-4])
or to allow only this year and subsequent five (of course, this would fail if it was 2006):
0[#right(1, year(now())#-#right(1, dateadd("y", year(now()))#]
to allow only the next 10 years, guaranteed to work in 3 years time (or whenever), create a list delimited by "|" with the two digit years in it
starting from this year and surround it in ().
So the regex allows you to control the data far more than *just* the format.
Paul
-- These lists are syncronised with the CFDeveloper forum at http://forum.cfdeveloper.co.uk/ Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/
CFDeveloper Sponsors and contributors:-
*Hosting and support provided by CFMXhosting.co.uk* :: *ActivePDF provided by
activepdf.com*
*Forums provided by fusetalk.com* :: *ProWorkFlow provided by proworkflow.com*
*Tutorials provided by helmguru.com* :: *Lists hosted by gradwell.com*To unsubscribe, e-mail: [EMAIL PROTECTED]
