How to check string is laid out in correct format (Python) -
i coding program needs import log files. user must input name of file in correct order of 'dd-hh.mm' (day, hour, minute). there way validate users input in correct order? thanks in advance you either use regular expressions, or try parse date time.strptime , see if there exceptions. see https://docs.python.org/2/library/time.html#time.strptime the strptime way this: try: time.strptime(input_string, "%d-%h.%m") except valueerror: print("incorrect date format") be sure check docs , see if placeholders ( %d , %h , ...) represent ranges , formats want check