DateValidator Class Reference
[Form example]

A validator that accepts dates. More...

#include <DateValidator.h>

Inheritance diagram for DateValidator:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 DateValidator (const boost::gregorian::date &bottom, const boost::gregorian::date &top)
 Construct a date validator.
virtual State validate (WString &input) const

Private Attributes

boost::gregorian::date bottom_
boost::gregorian::date top_


Detailed Description

A validator that accepts dates.

This example validator only accepts input in the dd/mm/yyyy format, and checks that the date is in the right range.

It would be a natural thing to extend this class to provide access to the parsed date as a boost::gregorian::date object for example.

This class is part of the Wt form example.

Definition at line 33 of file DateValidator.h.


Constructor & Destructor Documentation

DateValidator::DateValidator ( const boost::gregorian::date &  bottom,
const boost::gregorian::date &  top 
)

Construct a date validator.

The validator will accept only dates in the indicated range.


Member Function Documentation

WValidator::State DateValidator::validate ( WString input  )  const [virtual]

Reimplemented from Wt::WRegExpValidator.

Definition at line 26 of file DateValidator.C.

00027 {
00028   WValidator::State state = WRegExpValidator::validate(input);
00029 
00030   std::string text = input.toUTF8();
00031 
00032   if ((state == Valid) && !text.empty()) {
00033     boost::smatch what;
00034     boost::regex_match(text, what, boost::regex(regExp().toUTF8()));
00035 
00036     try {
00037       date d
00038         = from_string(what[3] + "/" + what[2] + "/" + what[1]);
00039 
00040       if ((d >= bottom_) && (d <= top_))
00041         return Valid;
00042       else
00043         return Invalid;
00044 
00045     } catch (std::exception& e) {
00046       return Invalid;
00047     }
00048   } else
00049     return state;
00050 }


Member Data Documentation

boost::gregorian::date DateValidator::bottom_ [private]

Definition at line 50 of file DateValidator.h.

boost::gregorian::date DateValidator::top_ [private]

Definition at line 50 of file DateValidator.h.


The documentation for this class was generated from the following files:

Generated on Fri Mar 26 17:12:12 2010 for Wt by doxygen 1.5.6