Latest Version: 0.9.6.2

CreditCardValidator

Checks that credit card numbers are valid (if not real).

You pass in the name of the field that has the credit card type and the field with the credit card number. The credit card type should be one of "visa", "mastercard", "amex", "dinersclub", "discover", "jcb".

You must check the expiration date yourself (there is no relation between CC number/types and expiration dates).

>>> cc = CreditCardValidator()
>>> cc.to_python({'ccType': 'visa', 'ccNumber': '4111111111111111'})
{'ccNumber': '4111111111111111', 'ccType': 'visa'}
>>> cc.to_python({'ccType': 'visa', 'ccNumber': '411111111111111'})
Traceback (most recent call last):
    ...
Invalid: ccNumber: You did not enter a valid number of digits
>>> cc.to_python({'ccType': 'visa', 'ccNumber': '411111111111112'})
Traceback (most recent call last):
    ...
Invalid: ccNumber: You did not enter a valid number of digits

Messages

badLength:
You did not enter a valid number of digits
badType:
The input must be a string (not a %(type)s: %(value)r)
empty:
Please enter a value
invalidNumber:
That number is not valid
noneType:
The input must be a string (not None)
notANumber:
Please enter only the number, no other characters

Attributes

a __singletonmethods__

('to_python', 'from_python')

a __unpackargs__

('cc_type_field', 'cc_number_field')

a accept_python

True

a cc_number_field

'ccNumber'

a cc_type_field

'ccType'

a compound

False

a not_empty

False

a repeating

False

a strip

False

Methods

f __call__(self, *args, **kw) ...

f __classinit__(cls, new_attrs) ...

f __classsourcerepr__(cls, source, binding=None) ...

f __init__(self, *args, **kw) ...

f __initargs__(self, new_attrs) ...

f __sourcerepr__(self, source, binding=None) ...

f validate_partial(self, field_dict, state) ...

f validate_python(self, field_dict, state) ...

See the source for more information.

Top