1
// Berkeley Open Infrastructure for Network Computing
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2005 University of California
5
// This is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation;
8
// either version 2.1 of the License, or (at your option) any later version.
10
// This software is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// To view the GNU Lesser General Public License visit
16
// http://www.gnu.org/copyleft/lesser.html
17
// or write to the Free Software Foundation, Inc.,
18
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
#if defined(__GNUG__) && !defined(__APPLE__)
21
#pragma implementation "ValidateEmailAddress.h"
25
#include "ValidateEmailAddress.h"
28
IMPLEMENT_DYNAMIC_CLASS(CValidateEmailAddress, wxValidator)
31
CValidateEmailAddress::CValidateEmailAddress(wxString *val) {
36
CValidateEmailAddress::CValidateEmailAddress(const CValidateEmailAddress& val)
43
CValidateEmailAddress::~CValidateEmailAddress() {}
46
bool CValidateEmailAddress::Copy(const CValidateEmailAddress& val) {
47
wxValidator::Copy(val);
49
m_stringValue = val.m_stringValue ;
55
bool CValidateEmailAddress::Validate(wxWindow *parent) {
59
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
61
if (!control->IsEnabled())
65
wxString val(control->GetValue().Trim().Trim(false)); // trim spaces before and after
67
// Regular Expression from Frank S. Thomas
69
wxT("^([^@]+)@([^@\\.]+)\\.([^@]{2,})$"));
71
if (val.Length() == 0) {
73
m_errormsg = _("Please specify an email address");
74
} else if (!reEmail.Matches(val)) {
76
m_errormsg = _("Invalid email address; please enter a valid email address");
80
wxASSERT_MSG(!m_errormsg.empty(), _T("you forgot to set errormsg"));
82
m_validatorWindow->SetFocus();
85
buf.Printf(m_errormsg, control->GetValue().c_str());
87
wxMessageBox(buf, _("Validation conflict"),
88
wxOK | wxICON_EXCLAMATION, parent
96
bool CValidateEmailAddress::TransferToWindow(void) {
103
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
104
control->SetValue(* m_stringValue) ;
110
bool CValidateEmailAddress::TransferFromWindow(void) {
111
if(!CheckValidator())
117
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
118
* m_stringValue = control->GetValue() ;
124
bool CValidateEmailAddress::wxIsAlphaNumeric(const wxString& val) {
126
for (i = 0; i < (int)val.Length(); i++) {
127
if (!wxIsalnum(val[i]))
134
bool CValidateEmailAddress::CheckValidator() const {
135
wxCHECK_MSG(m_validatorWindow, FALSE,
136
_T("No window associated with validator"));
137
wxCHECK_MSG(m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)), FALSE,
138
_T("wxTextValidator is only for wxTextCtrl's"));
139
wxCHECK_MSG(m_stringValue, FALSE,
140
_T("No variable storage for validator"));
1
// This file is part of BOINC.
2
// http://boinc.berkeley.edu
3
// Copyright (C) 2008 University of California
5
// BOINC is free software; you can redistribute it and/or modify it
6
// under the terms of the GNU Lesser General Public License
7
// as published by the Free Software Foundation,
8
// either version 3 of the License, or (at your option) any later version.
10
// BOINC is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
// See the GNU Lesser General Public License for more details.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18
#if defined(__GNUG__) && !defined(__APPLE__)
19
#pragma implementation "ValidateEmailAddress.h"
23
#include "ValidateEmailAddress.h"
24
#include "BOINCGUIApp.h"
27
IMPLEMENT_DYNAMIC_CLASS(CValidateEmailAddress, wxValidator)
30
CValidateEmailAddress::CValidateEmailAddress(wxString *val) {
35
CValidateEmailAddress::CValidateEmailAddress(const CValidateEmailAddress& val)
42
CValidateEmailAddress::~CValidateEmailAddress() {}
45
bool CValidateEmailAddress::Copy(const CValidateEmailAddress& val) {
46
wxValidator::Copy(val);
48
m_stringValue = val.m_stringValue ;
54
bool CValidateEmailAddress::Validate(wxWindow *parent) {
58
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
60
if (!control->IsEnabled())
64
wxString val(control->GetValue().Trim().Trim(false)); // trim spaces before and after
66
// Regular Expression from Frank S. Thomas
68
wxT("^([^@]+)@([^@\\.]+)\\.([^@]{2,})$"));
70
if (val.Length() == 0) {
72
m_errormsg = _("Please specify an email address");
73
} else if (!reEmail.Matches(val)) {
75
m_errormsg = _("Invalid email address; please enter a valid email address");
79
wxASSERT_MSG(!m_errormsg.empty(), _T("you forgot to set errormsg"));
81
m_validatorWindow->SetFocus();
84
buf.Printf(m_errormsg, control->GetValue().c_str());
86
wxGetApp().SafeMessageBox(buf, _("Validation conflict"),
87
wxOK | wxICON_EXCLAMATION, parent
95
bool CValidateEmailAddress::TransferToWindow(void) {
102
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
103
control->SetValue(* m_stringValue) ;
109
bool CValidateEmailAddress::TransferFromWindow(void) {
110
if(!CheckValidator())
116
wxTextCtrl *control = (wxTextCtrl *) m_validatorWindow ;
117
* m_stringValue = control->GetValue() ;
123
bool CValidateEmailAddress::wxIsAlphaNumeric(const wxString& val) {
125
for (i = 0; i < (int)val.Length(); i++) {
126
if (!wxIsalnum(val[i]))
133
bool CValidateEmailAddress::CheckValidator() const {
134
wxCHECK_MSG(m_validatorWindow, FALSE,
135
_T("No window associated with validator"));
136
wxCHECK_MSG(m_validatorWindow->IsKindOf(CLASSINFO(wxTextCtrl)), FALSE,
137
_T("wxTextValidator is only for wxTextCtrl's"));
138
wxCHECK_MSG(m_stringValue, FALSE,
139
_T("No variable storage for validator"));