Last active
December 14, 2015 05:58
-
-
Save Y4suyuki/5038766 to your computer and use it in GitHub Desktop.
Valid month, day and year
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Validation functions for month, day, and year | |
months = ['January', | |
'February', | |
'March', | |
'April', | |
'May', | |
'June', | |
'July', | |
'August', | |
'September', | |
'October', | |
'November', | |
'December'] | |
def valid_month(month): | |
if (month.lower()).capitalize() in months: | |
return month.capitalize() | |
else: | |
return None | |
def valid_day(day): | |
if day.isdigit(): | |
if int(day) <= 31 and int(day) > 0: | |
return int(day) | |
# valid_day('0') => None | |
# valid_day('1') => 1 | |
# valid_day('15') => 15 | |
# valid_day('500') => None | |
def valid_year(year): | |
if year.isdigit(): | |
year = int(year) | |
if year >= 1900 and year <= 2020: | |
return year | |
# valid_year('0') => None | |
# valid_year('-11') => None | |
# valid_year('1950') => 1950 | |
# valid_year('2000') => 2000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment