Reputation: 3
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
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