Validating Credit Card Numbers

  • + 0 comments
    import re
    
    cd_re = r'^(4|5|6)\d{3}(-*\d{4}){3}$'
    not_cd_re = r'(.)(-?\1-?){3}'
    
    for _ in range(int(input())):
        cd = input()
        print('Valid' if re.search(cd_re, cd) and not re.search(not_cd_re, cd) else 'Invalid')