1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- // ECOin - Copyright (c) - 2014/2021 - GPLv3 - epsylon@riseup.net (https://03c8.net)
- #include "ecoinaddressvalidator.h"
- EcoinAddressValidator::EcoinAddressValidator(QObject *parent) :
- QValidator(parent)
- {
- }
- QValidator::State EcoinAddressValidator::validate(QString &input, int &pos) const
- {
- // Correction
- for(int idx=0; idx<input.size();)
- {
- bool removeChar = false;
- QChar ch = input.at(idx);
- switch(ch.unicode())
- {
- case 0x200B: // ZERO WIDTH SPACE
- case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
- removeChar = true;
- break;
- default:
- break;
- }
- // Remove whitespace
- if(ch.isSpace())
- removeChar = true;
- // To next character
- if(removeChar)
- input.remove(idx, 1);
- else
- ++idx;
- }
- // Validation
- QValidator::State state = QValidator::Acceptable;
- for(int idx=0; idx<input.size(); ++idx)
- {
- int ch = input.at(idx).unicode();
- if(((ch >= '0' && ch<='9') ||
- (ch >= 'a' && ch<='z') ||
- (ch >= 'A' && ch<='Z')) &&
- ch != 'l' && ch != 'I' && ch != '0' && ch != 'O')
- {
- // Alphanumeric and not a 'forbidden' character
- }
- else
- {
- state = QValidator::Invalid;
- }
- }
- // Empty address is "intermediate" input
- if(input.isEmpty())
- {
- state = QValidator::Intermediate;
- }
- return state;
- }
|