Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions