How to determine if the string is valid There are certain criteria that the date in the slashes format must fit to be valid: The string must separate the day, month and year with slashes. This criteria makes the strings "03142022" or "10,24,2025" invalid date strings. Day, month, and year must be composed of digits only. This makes the string "Jan/12/2022" invalid. Note: .isdigit() function is perfect for checking if a string is numeric (if it can be converted to an integer) The month must be within 1 and 12. This criteria makes the string "13/28/2025" invalid. The day must be within the max days limit for a given month. For instance, there are only 30 days on November, but 31 days in December. Therefore, "11/31/2022" is invalid while "12/31/2022" is valid. You will have a dictionary for how many days each month has. For simplicity, let's assume that February always has 28 days. Requirements for the program Write a function validate_date(date_string) which takes in a datestring and checks if the datestring is valid. If the string is valid, we want to return a tuple containing True and the date_string itself. If the string is invalid for a specific reason, we want to return a tuple containing False and the error code explaining what was wrong with the date string passed in.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

How to determine if the string is valid

There are certain criteria that the date in the slashes format must fit to be valid:

  • The string must separate the day, month and year with slashes. This criteria makes the strings "03142022" or "10,24,2025" invalid date strings.

  • Day, month, and year must be composed of digits only. This makes the string "Jan/12/2022" invalid. Note: .isdigit() function is perfect for checking if a string is numeric (if it can be converted to an integer)

  • The month must be within 1 and 12. This criteria makes the string "13/28/2025" invalid.

  • The day must be within the max days limit for a given month. For instance, there are only 30 days on November, but 31 days in December. Therefore, "11/31/2022" is invalid while "12/31/2022" is valid. You will have a dictionary for how many days each month has. For simplicity, let's assume that February always has 28 days.

Requirements for the program

  • Write a function validate_date(date_string) which takes in a datestring and checks if the datestring is valid. If the string is valid, we want to return a tuple containing True and the date_string itself. If the string is invalid for a specific reason, we want to return a tuple containing False and the error code explaining what was wrong with the date string passed in.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education