Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am facing a problem of validating date & time according to local culture.

This is my RegularExpressionValidator

C#
<asp:RegularExpressionValidator
       ID="regTime"
       ControlToValidate="txtTime"
       Display="Dynamic"
       Text="Invalid Time Format"
       ValidationExpression="^((1[012])|(0?[1-9])):([0-5][0-9]) ?([aApP][mM])$"
       runat="server">
 </asp:RegularExpressionValidator>


The above validator validates time of en-en culture.

Now as I am developing an applications which needs to be able to handle date and time format of every culture, I want a concrete solution to how to validate date & time depending on culture using RegularExpression.

For example, American time format is h:mm tt (01:20 PM) & German time format is HH:mm (13:20).
Posted
Comments
Maciej Los 5-Aug-14 2:12am    
Sounds like AM/PM at then end of time string is not necessary. Adding {0,1} should resolve the problem.
?([aApP][mM]){0,1}$
markand911 5-Aug-14 2:23am    
You mean this way
^((1[012])|(0?[1-9])):([0-5][0-9]) ?([aApP][mM]){0,1}$

1 solution

try this Validation expression

@"^(([0-2]\d|[3][0-1])\.([0]\d|[1][0-2])\.[2][0]\d{2})$"
 
Share this answer
 

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