I'm using a CustomValidator in an ASP.NET page to validate the text in a TextBox as a Date-Time. I'm expecting pretty much only one format, "MM/DD/YYYY HH:MM PM". The TextBox is usually expecting to be filled by an associated DatePicker, but the user may still freeform it if they want.
Heres' the code, which seems to work. I am looking to see if there is any better JavaScript for this purpose.
function StartDateTimeValidate(source, args)
{
var d = Date.parse(args.Value);
if (isNaN(d))
{
args.IsValid = false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="StartDateCalendarTextBox" runat="server" Width="200"></asp:TextBox>
<asp:CustomValidator ID="StartDateCustomValidator" runat="server"
ErrorMessage="Bad Date"
ClientValidationFunction="StartDateTimeValidate"
ValidateEmptyText="false"
ControlToValidate="StartDateCalendarTextBox"
></asp:CustomValidator>