I have an input date:
<p><label for="issue">Issue:</label>
<input type="text" name="issue" value="@issue" size="150"/></p>
<p><label for="inClockIn">ClockIn:</label>
<input type="text" size="25" name="inCI" value="@inClockIn" /></p>
and I have code to handle the input:
if(IsPost){
issue = Request.Form["issue"];
inClockIn = Request.Form["inCI"];
clockIn = DateTime.ParseExact(inClockIn, dateFormat, null);
issueId = Request.Form["issueId"];
Validation.RequireField("issue", "You must enter an issue");
Validation.Add("clockIn" , Validator.Required("Clock In"), Validator.DateTime());
if(Validation.IsValid()){
var db = Database.Open("Issues");
var updateCommand =
"UPDATE IssueTable SET Issue=@0, ClockIn=@1, ClockOut=@2, Billed=@3 WHERE Id=@4";
db.Execute(updateCommand, issue, clockIn, clockOut, billed, issueId);
Response.Redirect("~/Issues");
}
}
one other variable to show:
var dateFormat = "MM/dd/yyyy HH:mm";
My problem is that Validation IS NOT Valid.
This is with a date field of "11/10/2012 08:00"
I suspect that the Validator.DateTime() is somewhat off the mark, but i can't find any documentation for it.
After all, how does it know that I want to validate the date in the format "MM/dd/yyyy HH:mm"?
Anyway, can someone please shed some light on this?
Thanks,
JJW
jackwebb2201...
0 Points
2 Posts
Date Validation problem
Nov 12, 2012 08:13 PM|LINK
I have an input date: <p><label for="issue">Issue:</label> <input type="text" name="issue" value="@issue" size="150"/></p> <p><label for="inClockIn">ClockIn:</label> <input type="text" size="25" name="inCI" value="@inClockIn" /></p> and I have code to handle the input: if(IsPost){ issue = Request.Form["issue"]; inClockIn = Request.Form["inCI"]; clockIn = DateTime.ParseExact(inClockIn, dateFormat, null); issueId = Request.Form["issueId"]; Validation.RequireField("issue", "You must enter an issue"); Validation.Add("clockIn" , Validator.Required("Clock In"), Validator.DateTime()); if(Validation.IsValid()){ var db = Database.Open("Issues"); var updateCommand ="UPDATE IssueTable SET Issue=@0, ClockIn=@1, ClockOut=@2, Billed=@3 WHERE Id=@4"; db.Execute(updateCommand, issue, clockIn, clockOut, billed, issueId); Response.Redirect("~/Issues"); } } one other variable to show: var dateFormat = "MM/dd/yyyy HH:mm"; My problem is that Validation IS NOT Valid. This is with a date field of "11/10/2012 08:00" I suspect that the Validator.DateTime() is somewhat off the mark, but i can't find any documentation for it.aarsh
Participant
1543 Points
427 Posts
Re: Date Validation problem
Nov 12, 2012 09:08 PM|LINK
Looks like it is a required field adn you want to force the user to enter a valid date. Let's break it as two validators