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 gettextargs

{}

a cc_type_field

'ccType'

a strip

False

a accept_python

True

a validate_partial_python

None

a __singletonmethods__

('to_python', 'from_python', 'message', 'all_messages', 'subvalidators')

a declarative_count

48

a use_builtins_gettext

True

a __unpackargs__

('cc_type_field', 'cc_number_field')

a validate_partial_form

True

a compound

False

a not_empty

False

a validate_partial_other

None

a __mutableattributes__

()

a repeating

False

a cc_number_field

'ccNumber'

Methods

f __initargs__(self, new_attrs) ...

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

f __classinit__(cls, new_attrs) ...

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

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

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

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

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

See the source for more information.