Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ between
.. autofunction:: between



btc_address
------

.. module:: validators.btc_address

.. autofunction:: btc_address




domain
------

Expand Down
20 changes: 20 additions & 0 deletions tests/test_btc_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
import pytest

from validators import btc_address, ValidationFailure


@pytest.mark.parametrize(('address',), [
('17nuNm4QpgKuDvWy7Jh2AZ2nzZpMyKSKzT',),
('3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69',),
])
def test_returns_true_on_valid_mac_address(address):
assert btc_address(address)


@pytest.mark.parametrize(('address',), [
('ff3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69',),
('b3Cgwgr2g7vsi1bXyjyDUkphEnVoRLA9w4FZfC69',),
])
def test_returns_failed_validation_on_invalid_mac_address(address):
assert isinstance(btc_address(address), ValidationFailure)
3 changes: 2 additions & 1 deletion validators/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .between import between
from .btc_address import btc_address
from .card import (
amex,
card_number,
Expand Down Expand Up @@ -29,6 +30,6 @@
'ipv4_cidr', 'ipv6', 'ipv6_cidr', 'length', 'mac_address', 'slug',
'truthy', 'url', 'ValidationFailure', 'validator', 'uuid',
'card_number', 'visa', 'mastercard', 'amex', 'unionpay', 'diners',
'jcb', 'discover')
'jcb', 'discover', 'btc_address')

__version__ = '0.16.0'
23 changes: 23 additions & 0 deletions validators/btc_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import re

from .utils import validator

pattern = re.compile(r"^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$")


@validator
def btc_address(value):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a doc block here defining how this function is to be used. See other functions of similar doc blocks. Also reference this doc block in the index.rst file

"""
Return whether or not given value is a valid bitcoin address.

If the value is valid bitcoin address this function returns ``True``,
otherwise :class:`~validators.utils.ValidationFailure`.

Examples::

>>> btc_address('3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69')
True

:param value: Bitcoin address string to validate
"""
return pattern.match(value)