I need a textbox for Date of birth?

Posted by Iluvdotnetfunda under ASP.NET on 4/19/2012 | Points: 10 | Views : 9171 | Status : [Member] | Replies : 7
Hello Friends,

I need a textbox for date of birth field in the format DOB - DATE in DD-MM-YYYY

Please help me.

Thanks
iluvdotnetfunda




Responses

Posted by: Leila on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
you can use the regex expression to avoid the user entering another format taht you want.

Thanks,
Leila

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
Go for ajax calender extender

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx

With this you can format the date you are entering, Direct selection of date.No need to worry that users will input an invalid format.

Enjoy Coding :)



____________
www.flickr.com/photos/psdesigner/

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sunny4989 on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
format date with

format(datefield,"mm/dd/yyyy")

------------------------------------------------
Learn throughout life

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sunny4989 on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
<asp:Textbox runat="server" ID="TextBox1" />
<asp:CustomValidator runat="server" ControlToValidate="TextBox1" ErrorMessage="Date was in incorrect format" OnServerValidate="CustomValidator1_ServerValidate" />


protected void CustomValidator1_ServerValidate(object sender, ServerValidateEventArgs e)
{
DateTime d;
e.IsValid = DateTime.TryParseExact(e.Value, "DD-MM-YYYY ", CultureInfo.InvariantCulture, DateTimeStyles.None, out d);
}


------------------------------------------------
Learn throughout life

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: dhirenkaunar-15094 on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
using javascript :

<script type="text/javascript">
function test() {
var a = new Date();
// a = "11022012";
a = document.getElementById("txt1").value;
var count = a.match(/-/g);

if (count == null) {
if (a.length == 8) {
var date = a.substr(0, 2);
var month = a.substr(2, 2);
var year = a.substr(4, 4);

if (date > 31 || month > 12) {
alert("enter valid date/month");
}
else {
document.getElementById("txt1").value = date + "-" + month + "-" + year;
}

}
else {
alert("please enter valid date");
}
}
}
</script>
<input type="text" id="txt1" onblur="test()" />


Thanks & Rgards,
Dhiren Kumar Kaunar

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sunny4989 on: 4/19/2012 [Member] Starter | Points: 25

Up
0
Down
Use Javascripts

In that go for regular expression.............

------------------------------------------------
Learn throughout life

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 4/19/2012 [Member] Bronze | Points: 25

Up
0
Down
Plz Check This Link

You might be useful


http://www.dotnetfunda.com/codes/code2224-given-date-to-change-the-date-formate.aspx

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Iluvdotnetfunda, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response