Click here to Skip to main content
14,920,094 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

My requirement is as follows:
I want a text box which will accept CSV values and the values can be any time of a day, ie. in one text box I can enter multiple clock times separated by comma. Hour and Minutes will be separated by a colon, Seconds not required.

If a.m. or p.m. can be associated it would be great [0-12 basis], otherwise 0-24 basis will be fine.

Accepted Inputs: 1:00, 12:45, 23:59, 11:34
Thanks in advance.
Posted
Updated 13-Mar-21 5:16am
v2
Comments
Dalek Dave 7-Sep-10 4:59am
   
Edited for Readability, Grammar and Code Block removal.

What have you attempted so far?

Show us your code.
   
Comments
avishekrc 7-Sep-10 5:34am
   
Hi,
I have got RegEx for time:
^([0-1]?[0-9]|[2][0-3]):([0-5][0-9])$
And for CSV:
[0-9]+(,[0-9]+)*
But I need to combine them.
Got the answer from ASP.Net forum,here it is:
Time Input : 1:00 AM, 12:45pm,03:59am,11:34 aM, ...
RegEx : (([0]?[1-9]|[0-1][0-2]):([0-5][0-9])( )?(AM|am|aM|Am|PM|pm|pM|Pm))+((,)( )?(([0]?[1-9]|[0-1][0-2]):([0-5][0-9])( )?(AM|am|aM|Am|PM|pm|pM|Pm))+)*
-------------
Time Input : 1:15,15:45, 23:59,00:34, 02:05
RegEx : (([0]?[0-9]|[1][0-9]|[2][0-3]):([0-5][0-9]))+((,)( )?(([0]?[0-9]|[1][0-9]|[2][0-3]):([0-5][0-9]))+)*
-------------
Time Input : 1:15,03:59am,15:45, 23:59,00:34, 11:34 aM,02:05, 1:00 AM, 12:45pm
RegEx : ((([0]?[1-9]|[0-1][0-2]):([0-5][0-9])( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[0-9]|[1][0-9]|[2][0-3]):([0-5][0-9])))+((,)( )?((([0]?[1-9]|[0-1][0-2]):([0-5][0-9])( )?(AM|am|aM|Am|PM|pm|pM|Pm))|(([0]?[0-9]|[1][0-9]|[2][0-3]):([0-5][0-9])))+)*

-------------
Hope it helps someone else!
   
Comments
Hiren solanki 6-Oct-10 1:57am
   
Thank you for sharing your answer.
Member 15099248 13-Mar-21 11:16am
   
@avishekrc Hey need help to create regex for 10:00AM-11:00AM or 10:00AM-11:00AM, 12:00PM-2:00PM… time range can be single or multiple

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900