From: Jay Pangmi Date: 2008-08-24T17:50:25+09:00 Subject: Re: setting date format to validate date in ruby Thomas B. wrote: > You can have a look at this post: > http://al2o3-cr.blogspot.com/2008/08/downloading-file.html . There's > date validation in it, in the very general form, working with any > separator and any number of digits. It uses scanning for digit groups. > > TPR. wow.. man that was cool, specially for the beginner like me. Thanks a tonn. Anyway, I figured one solution out for me here's the code: ================================================================================ for mydate in dateArray if %r{(\d{1,2})/(\d{1,2})/(\d{4})} =~ mydate or %r{(\d{1,2}):(\d{1,2}):(\d{4})} =~ mydate or %r{(\d{1,2}) (\d{1,2}) (\d{4})} =~ mydate mday, month, year = $1.to_i, $2.to_i, $3.to_i if Date.valid_civil?(year,month,mday) #virtualArray << mydate puts "Valid Date: " << mydate else puts "Invalid Date: " << mydate end end end ================================================================================ One really cool thing about Date.valid_civil? is that it return false even if the date doesn't exist in the calender no matter how right the format is. Now what is bothering me is the logic to sort out the dates in the array. I tried the simplest way "Array.sort" but it only sorted the array according to the first value it sees not the whole date. How can I sort it out. Thanks -- Posted via http://www.ruby-forum.com/.