Using regular expression, how would I validate a date to make sure it is only entered in this format: mm/dd/yyyy?
If anyone is interested, I'm using validates_format_of :date_field, :with => //
in a Ruby model.
Regex for this format can looks like:
^\d{2}\/\d{2}\/\d{4}$
@hsz answer is correct. Should you need to also validate the date itself you can use this :
/^(?:0?[1-9]|1[0-2])/(?:0?[1-9]|[1-2]\d|3[01])/\d{4}$/
Edit :
As @Tim said this will is not a 100% regex validator. See his linked answer for that.
if subject =~ /\A(?:0?[1-9]|1[0-2])\/(?:0?[1-9]|[1-2]\d|3[01])\/\d{4}\Z/
# Successful match
Edit #2 : Ruby specific version above.
DateTime.strptime
with the appropriate format string and an exception handler would be much better.