diff --git a/core/misc.cpp b/core/misc.cpp index ee7534f..30646f7 100755 --- a/core/misc.cpp +++ b/core/misc.cpp @@ -622,11 +622,11 @@ std::wstring::size_type i; } - -bool IsEmailCorrectChar(wchar_t c) -{ -bool correct = false; - + +bool IsEmailCorrectChar(wchar_t c) +{ +bool correct = false; + const wchar_t * allowed_chars = L"@.!#$%&'*+-/=?^_`{|}~"; if( (c >= 'A' && c<='Z') || @@ -646,12 +646,12 @@ bool correct = false; } } } - -return correct; -} - - - + +return correct; +} + + + bool ValidateEmail(const wchar_t * email) { int at = 0; // how many '@' @@ -674,13 +674,13 @@ bool ValidateEmail(const wchar_t * email) return true; } - - + + bool ValidateEmail(const std::wstring & email) { - return ValidateEmail(email.c_str()); -} - + return ValidateEmail(email.c_str()); +} + diff --git a/core/misc.h b/core/misc.h index 1c7a570..7f62fae 100755 --- a/core/misc.h +++ b/core/misc.h @@ -258,6 +258,42 @@ void MaxSize(StringType & str, size_t max_size) +/* + this method removing all characters from given string + only digits are allowed and if allow_comma then one comma (or dot) + character is allowed +*/ +template +void OnlyDigit(StringType & s, bool allow_comma = true) +{ +typename StringType::size_type i; +bool was_comma = false; + + if( s.empty() ) + { + s = '0'; + return; + } + + for(i=0 ; i='0' && s[i]<='9') || + (allow_comma && !was_comma && (s[i]=='.' || s[i]==',')) ) + { + if( s[i]=='.' || s[i]==',' ) + was_comma = true; + + i += 1; + } + else + { + s.erase(i, 1); + } + } +} + + + wchar_t ToSmall(wchar_t c); void ToSmall(std::wstring & s);