| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 1 |
+#include <wx/object.h> |
|
| 2 |
+#include <wx/string.h> |
|
| 3 |
+#include "RegExValidator.h" |
|
| 4 |
+ |
|
| 5 |
+RegExValidator::RegExValidator(wxString regExpString, wxString *valPtr, int regExpFlags) : wxTextValidator(wxFILTER_EMPTY, valPtr), regEx(regExpString, regExpFlags), regExString(regExpString), regExFlags(regExpFlags) |
|
| 6 |
+{
|
|
| 7 |
+} |
|
| 8 |
+ |
|
| 9 |
+wxObject *RegExValidator::Clone() const |
|
| 10 |
+{
|
|
| 11 |
+ return new RegExValidator(this->regExString, this->m_stringValue, this->regExFlags); |
|
| 12 |
+} |
|
| 13 |
+ |
|
| 14 |
+wxString RegExValidator::IsValid(const wxString &str) const |
|
| 15 |
+{
|
|
| 16 |
+ if (!this->regEx.Matches(str)) |
|
| 17 |
+ return "Invalid format."; |
|
| 18 |
+ |
|
| 19 |
+ return wxTextValidator::IsValid(str); |
|
| 20 |
+} |
| 0 | 21 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,18 @@ |
| 1 |
+#pragma once |
|
| 2 |
+ |
|
| 3 |
+#include <wx/object.h> |
|
| 4 |
+#include <wx/regex.h> |
|
| 5 |
+#include <wx/string.h> |
|
| 6 |
+#include <wx/valtext.h> |
|
| 7 |
+ |
|
| 8 |
+class RegExValidator : public wxTextValidator |
|
| 9 |
+{
|
|
| 10 |
+protected: |
|
| 11 |
+ wxRegEx regEx; |
|
| 12 |
+ wxString regExString; |
|
| 13 |
+ int regExFlags; |
|
| 14 |
+public: |
|
| 15 |
+ RegExValidator(wxString regExpString, wxString *valPtr = nullptr, int regExpFlags = wxRE_DEFAULT); |
|
| 16 |
+ wxObject *Clone() const override; |
|
| 17 |
+ wxString IsValid(const wxString &str) const override; |
|
| 18 |
+}; |