Question: In this assignment you will use regular expression How to validate time in 2 4 - hour format using Regular Expression Given a string str

In this assignment you will use regular expression
How to validate time in 24-hour format using Regular Expression
Given a string str, the task is to check whether the string is valid time in 24-hour format or not
by using Regular Expression.
The valid time in the 24-hour format must satisfy the following conditions.
1. It should start from 0-23 or 00-23.
2. It should be followed by a :'(colon).
3. It should be followed by two digits from 00 to 59.
4. It should not end with am,pm or AM,PM.
Examples:
Input: str =13:05
Output: true
Explanation: The given string satisfies all the above mentioned conditions.
Input: str =02:15
Output: true
Explanation: The given string satisfies all the above mentioned conditions.
Input: str =24:00
Output: false
Explanation: The given string doesnt be in the range of 0-23 or 00-23(i.e., hour is out of
range), therefore it is not a valid time in 24-hour format.
Input: str =10:60
Output: false
Explanation: The given string doesnt be in the range of 00 to 59(i.e., minute is out of range),
therefore it is not a valid time in 24-hour format.
Input: str =10:15 PM
Output: false
Explanation: The given string end with AM or PM, therefore it is not a valid time in 24-hour
format.
Note : You are recommended to use Java

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!