From: 7stud -- Date: 2009-09-08T01:32:45+09:00 Subject: Re: Date & time validation Ne Scripter wrote: > Just an update of where I am. This is what I have > > if date =~ (/\d{4}\/\d{2}\/\d{2}/) > puts date > else > date = (Date.strptime(date, "%Y/%m/%d")) > end > > This works to an extent but does not deal with a string which contains a > valid date but still invalid data like so > > 2009/09/07 12:12:12 > > This would be passed as valid when it is not only a string containing > yyyy/mm/dd. > > Any ideas? > > Thanks a lot > Look at the regex's in all the following examples. How do they differ from your regex? >> Robert Klemme wrote: >>> 2009/9/1 Brian Candler : >>>> Max Williams wrote: >>>>>/^\d{4}\/\d{2}\/\d{2}$/) >>>> >>>> Beware: use >>>> >>>> /\A\d{4}\/\d{2}\/\d{2}\z/ >>>> >>> %r{\A(\d{4})/(\d{2})/(\d{2})\z} .. . . . . . . .. -- Posted via http://www.ruby-forum.com/.