Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2011-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <qt/bitcoinaddressvalidator.h>7#include <key_io.h>9/* Base58 characters are:10"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"12This is:13- All numbers except for '0'14- All upper-case letters except for 'I' and 'O'15- All lower-case letters except for 'l'16*/18BitcoinAddressEntryValidator::BitcoinAddressEntryValidator(QObject *parent) :19QValidator(parent)20{21}23QValidator::State BitcoinAddressEntryValidator::validate(QString &input, int &pos) const24{25Q_UNUSED(pos);27// Empty address is "intermediate" input28if (input.isEmpty())29return QValidator::Intermediate;31// Correction32for (int idx = 0; idx < input.size();)33{34bool removeChar = false;35QChar ch = input.at(idx);36// Corrections made are very conservative on purpose, to avoid37// users unexpectedly getting away with typos that would normally38// be detected, and thus sending to the wrong address.39switch(ch.unicode())40{41// Qt categorizes these as "Other_Format" not "Separator_Space"42case 0x200B: // ZERO WIDTH SPACE43case 0xFEFF: // ZERO WIDTH NO-BREAK SPACE44removeChar = true;45break;46default:47break;48}50// Remove whitespace51if (ch.isSpace())52removeChar = true;54// To next character55if (removeChar)56input.remove(idx, 1);57else58++idx;59}61// Validation62QValidator::State state = QValidator::Acceptable;63for (int idx = 0; idx < input.size(); ++idx)64{65int ch = input.at(idx).unicode();67if (((ch >= '0' && ch<='9') ||68(ch >= 'a' && ch<='z') ||69(ch >= 'A' && ch<='Z')) &&70ch != 'I' && ch != 'O') // Characters invalid in both Base58 and Bech3271{72// Alphanumeric and not a 'forbidden' character73}74else75{76state = QValidator::Invalid;77}78}80return state;81}83BitcoinAddressCheckValidator::BitcoinAddressCheckValidator(QObject *parent) :84QValidator(parent)85{86}88QValidator::State BitcoinAddressCheckValidator::validate(QString &input, int &pos) const89{90Q_UNUSED(pos);91// Validate the passed Bitcoin address92if (IsValidDestinationString(input.toStdString())) {93return QValidator::Acceptable;94}96return QValidator::Invalid;97}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.