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 hour format using Regular Expression
Given a string str the task is to check whether the string is valid time in hour format or not
by using Regular Expression.
The valid time in the hour format must satisfy the following conditions.
It should start from or
It should be followed by a :colon
It should be followed by two digits from to
It should not end with ampm or AMPM
Examples:
Input: str :
Output: true
Explanation: The given string satisfies all the above mentioned conditions.
Input: str :
Output: true
Explanation: The given string satisfies all the above mentioned conditions.
Input: str :
Output: false
Explanation: The given string doesnt be in the range of or ie hour is out of
range therefore it is not a valid time in hour format.
Input: str :
Output: false
Explanation: The given string doesnt be in the range of to ie minute is out of range
therefore it is not a valid time in hour format.
Input: str : PM
Output: false
Explanation: The given string end with AM or PM therefore it is not a valid time in 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
