user2637054
user2637054

Reputation: 3

Validate input 16-digit credit card number

I need to validate an input string that should contain exactly 16 integer digits, no more, no less. How can I do it?

Upvotes: 0

Views: 1065

Answers (1)

falsetru
falsetru

Reputation: 369064

Check length using len. Use str.isdigit to check the string contain only digits.

>>> valid = '1234567890123456'
>>> invalid = '1848934798237489324324'
>>> len(valid) == 16 and valid.isdigit()
True
>>> len(invalid) == 16 and invalid.isdigit()
False

Upvotes: 1

Related Questions