Friday, February 11, 2011

String Date validation C# asp.net

using

System;

using

System.Collections.Generic;

using

System.Linq;

using

System.Web;

using

System.Web.UI;

using

System.Web.UI.WebControls;

public

partial class Default5 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

private bool ValidateDate(string date)

{

try

{

string[] dateParts = date.Split('/');

DateTime testDate = new

DateTime(Convert.ToInt32(dateParts[2]),

Convert.ToInt32(dateParts[0]),

Convert.ToInt32(dateParts[1]));

Response.Write(

"No error ");

return true;

}

catch

{

Response.Write(

"error");

return false;

}

}

protected void Button1_Click(object sender, EventArgs e)

{

ValidateDate(TextBox1.Text);

}

}

No comments: