1 // Copyright (c) 2011-2014 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #include "bitcoinaddressvalidator.h"
9 /* Base58 characters are:
10 "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
13 - All numbers except for '0'
14 - All upper-case letters except for 'I' and 'O'
15 - All lower-case letters except for 'l'
18 BitcoinAddressEntryValidator::BitcoinAddressEntryValidator(QObject
*parent
) :
23 QValidator::State
BitcoinAddressEntryValidator::validate(QString
&input
, int &pos
) const
27 // Empty address is "intermediate" input
29 return QValidator::Intermediate
;
32 for (int idx
= 0; idx
< input
.size();)
34 bool removeChar
= false;
35 QChar ch
= input
.at(idx
);
36 // Corrections made are very conservative on purpose, to avoid
37 // users unexpectedly getting away with typos that would normally
38 // be detected, and thus sending to the wrong address.
41 // Qt categorizes these as "Other_Format" not "Separator_Space"
42 case 0x200B: // ZERO WIDTH SPACE
43 case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE
62 QValidator::State state
= QValidator::Acceptable
;
63 for (int idx
= 0; idx
< input
.size(); ++idx
)
65 int ch
= input
.at(idx
).unicode();
67 if (((ch
>= '0' && ch
<='9') ||
68 (ch
>= 'a' && ch
<='z') ||
69 (ch
>= 'A' && ch
<='Z')) &&
70 ch
!= 'l' && ch
!= 'I' && ch
!= '0' && ch
!= 'O')
72 // Alphanumeric and not a 'forbidden' character
76 state
= QValidator::Invalid
;
83 BitcoinAddressCheckValidator::BitcoinAddressCheckValidator(QObject
*parent
) :
88 QValidator::State
BitcoinAddressCheckValidator::validate(QString
&input
, int &pos
) const
91 // Validate the passed Bitcoin address
92 CBitcoinAddress
addr(input
.toStdString());
94 return QValidator::Acceptable
;
96 return QValidator::Invalid
;