#include <DateValidator.h>
Public Member Functions | |
DateValidator (const boost::gregorian::date &bottom, const boost::gregorian::date &top) | |
Construct a date validator. | |
virtual State | validate (WString &input, int &pos) const |
Private Attributes | |
boost::gregorian::date | bottom_ |
boost::gregorian::date | top_ |
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.
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.
WValidator::State DateValidator::validate | ( | WString & | input, | |
int & | pos | |||
) | const [virtual] |
Reimplemented from Wt::WRegExpValidator.
Definition at line 25 of file DateValidator.C.
00026 { 00027 WValidator::State state = WRegExpValidator::validate(input, pos); 00028 00029 std::string text = input.toUTF8(); 00030 00031 if ((state == Valid) && !text.empty()) { 00032 boost::smatch what; 00033 boost::regex_match(text, what, regExp()); 00034 00035 try { 00036 date d 00037 = from_string(what[3] + "/" + what[2] + "/" + what[1]); 00038 00039 if ((d >= bottom_) && (d <= top_)) 00040 return Valid; 00041 else 00042 return Invalid; 00043 00044 } catch (std::exception& e) { 00045 return Invalid; 00046 } 00047 } else 00048 return state; 00049 }
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.