Add a RegEx validator for use with wxWidgets.
--- /dev/null
+++ b/src/in_xsf_framework/RegExValidator.cpp
@@ -1,1 +1,21 @@
+#include <wx/object.h>
+#include <wx/string.h>
+#include "RegExValidator.h"
+RegExValidator::RegExValidator(wxString regExpString, wxString *valPtr, int regExpFlags) : wxTextValidator(wxFILTER_EMPTY, valPtr), regEx(regExpString, regExpFlags), regExString(regExpString), regExFlags(regExpFlags)
+{
+}
+
+wxObject *RegExValidator::Clone() const
+{
+ return new RegExValidator(this->regExString, this->m_stringValue, this->regExFlags);
+}
+
+wxString RegExValidator::IsValid(const wxString &str) const
+{
+ if (!this->regEx.Matches(str))
+ return "Invalid format.";
+
+ return wxTextValidator::IsValid(str);
+}
+
--- /dev/null
+++ b/src/in_xsf_framework/RegExValidator.h
@@ -1,1 +1,19 @@
+#pragma once
+#include <wx/object.h>
+#include <wx/regex.h>
+#include <wx/string.h>
+#include <wx/valtext.h>
+
+class RegExValidator : public wxTextValidator
+{
+protected:
+ wxRegEx regEx;
+ wxString regExString;
+ int regExFlags;
+public:
+ RegExValidator(wxString regExpString, wxString *valPtr = nullptr, int regExpFlags = wxRE_DEFAULT);
+ wxObject *Clone() const override;
+ wxString IsValid(const wxString &str) const override;
+};
+