views:

7359

answers:

3

Can anyone tell me the regular expression format for "MM/DD/YY HH:mm:ss AM/PM" to use it in a regular expression validator, in asp.net 2.0

+2  A: 

I highly recommend that you do not use regex for this. Instead, you should create your own validator (inherit BaseValidator) and use DateTime.TryParseExact to check that the value can be converted to DateTime.

apathetic
but i want to validate this on client side,i should not go to server side and validate.And one more thing is if I use client click for the button, all other required validators are not working. Please suggest
+1  A: 

For client-side (JavaScript) validation, you can use

^\d\d/\d\d/\d\d \d\d:\d\d:\d\d [AP]M$

which will check syntax (digits, spaces, separators), strictly, against your spec. If a match is obtained, you then need to check the ranges of the values entered (e.g. 1 <= month <= 12, etc.) in the subgroups for the returned match.

Use this site to test out the regex.

Vinay Sajip
A: 

Can you try this

(0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])/\d\d (0[0-9]|1[0-9]|2[0-4]):([0-5][0-9]):([0-5][0-9]) [AM|PM]

Hope it solves your problem.

Izabela