<asp:TextBox ID="txtdob" TextMode="Date" CssClass="form-control" placeholder="DOB"
onfocus="(this.type='date')" runat="server"></asp:TextBox>
The placeholder date should be filled with the date of birth value.
Related
I want to disable future dates
This is what I am trying <Asp:TextBox ID="TextBox4" runat="server" TextMode="Date" ClientIDMode="Static"/>
I am expecting when user try to enter a date it will shows only current date not future date
I want to change the format of the date while binding the value of the date to the gridview (02-oct-2019) like this
I have tried this :
Text='<%# Eval("InsertDateTime","{0:dd-mmm-yyy}") %>'
"this label is inside the gridview"
<asp:Label ID="lblInsertDateTime" runat="server" Text='<%# Eval("InsertDateTime","{0:dd-mmm-yyy}") %>'></asp:Label>
I want to enter dates into my database using asp.net form-view but my challenge is that the dates once entered like 04 jun 2018, when I go to edit the template it will display as 4/06/2018 12:00:00 a.m.
So the system will crash if I hit update, I have learnt that this 4/06/2018 12:00:00 a.m. is the cause for crush as the server will respond with datatype mismatch.
How can I display the date in my text box in edit template like 04/06/2018 12:00:00 am as this is a valid date format?
It's working fine with local machine and the problem is when hosted it on Windows Server 2012.
Below is a textbox in my EditItemTemplate
ApplicDate:
<asp:TextBox
ID="ApplicDateTxtBox"
EnableViewState="true" runat="server"
Text='<%# Bind("ApplicDate") %>' TextMode="singleline" />
<asp:RegularExpressionValidator
ID="RegularExpressionValidator3"
runat="server"
ForeColor="red"
ErrorMessage="Incorrect date format: example 15 feb 2018!"
ValidationExpression="^([1-9]|[12][0-9]|3[01])[-/.](0[1-9]|1[012])[-/.](19|20)\d\d\s\d{2}\:\d{2}\:\d{2}\s\w{1}\.\w{1}\.$|(0[1-9]|[12][0-9]|3[01])[-/.](0[1-9]|1[012])[-/.](19|20)\d\d\s\d{2}\:\d{2}\:\d{2}\s\w{1}\.\w{1}\.$|(0[1-9]|[12][0-9]|3[01])[-/.](0[1-9]|1[012])[-/.](19|20)\d\d\s\d{2}\:\d{2}\:\d{2}\s\w{2}$|(0[1-9]|[12][0-9]|3[01])\s\w{3}\s(19|20)\d\d$"
ControlToValidate="ApplicDateTxtBox">
</asp:RegularExpressionValidator>
You can set the date format with BoundField.DataFormatString
For your case, it should be formatted as G for
General date/time pattern (long time).
Specify this to FormView binding Field as
<%# Bind("<BINDING DATE COLUMN>", "{0:G}") %>
For your case,
<asp:TextBox ID="ApplicDateTxtBox" EnableViewState="true" runat="server" Text='<%# Bind("CheckDate", "{0:G}") %>' TextMode="singleline" />
I have a TextBox where I am taking input from as user as dd/mm/yyyy hh:mm:ss. Now, I want to validate it with a regular expression. I'm not sure how to apply the expression. I have attached my code as well.
<tr>
<td style="width: 30%" class="EcommLabel">
Date From
</td>
<td style="width: 70%" class="EcommLabel">
<asp:TextBox ID="txtDateFrom" CssClass="EcommNormalTextBox" runat="server">
</asp:TextBox>MM/DD/YYYY<br />
<%-- <asp:RegularExpressionValidator ID="regDateFrom" ValidationExpression="^(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))$" ControlToValidate="txtDateFrom" ValidationGroup="Promotion" runat="server" ErrorMessage="Invalid Date"></asp:RegularExpressionValidator>--%>
<asp:RangeValidator runat="server" ID="rvDateFrom" Type="Date" ControlToValidate="txtDateFrom" MaximumValue="3000/12/31" MinimumValue="2000/1/1" ErrorMessage="Invalid Date" Display="Dynamic" ValidationGroup="Promotion" />
</td>
</tr>
use this expression "(\d{2}):(\d{2}):(\d{4}):(\d{2}):(\d{2}):(\d{2})" like
<asp:RegularExpressionValidator ID="regDateFrom" ValidationExpression="(\d{2}):(\d{2}):(\d{4}):(\d{2}):(\d{2}):(\d{2})"
ControlToValidate="txtDateFrom" ValidationGroup="Promotion" runat="server"
ErrorMessage="Invalid Date"></asp:RegularExpressionValidator>
Also see the following stackoverflow questions:
How to write a regex for MM:DD:YYYY:HH:MM:SS
MM/DD/YYYY HH:MM:SS AM/PM date validation regular expression in javascript
Hope it helps!
Change of your regular expression would do it.
Use the following regular expression
^([1-9]|([012][0-9])|(3[01]))-([0]{0,1}[1-9]|1[012])-\d\d\d\d [012]{0,1}[0-9]:[0-5][0-9]:[0-5][0-9]$
It will validate the value 01-12-2011 19:59:59
<asp:RegularExpressionValidator ID="regDateFrom"
ValidationExpression="^([1-9]|([012][0-9])|(3[01]))-([0]{0,1}[1-9]|1[012])-\d\d\d\d [012]{0,1}[0-9]:[0-5][0-9]:[0-5][0-9]$"
ControlToValidate="txtDateFrom" ValidationGroup="Promotion"
runat="server"
ErrorMessage="Invalid Date">
</asp:RegularExpressionValidator>
I have a date picker where I am taking input from as user as MM/DD/YYYY. I want to validate it with a regular expression. Find Below code it might be help full.
expression = "^([0]{0,1}[1-9]|1[012])/([1-9]|([012][0-9])|(3[01]))/[0-9]{4}$";
i have a repeater in my asp.net page and bind a data source to this repeater
there is a label in this repeater and the text of label is a datetime field
i want that label only show me the date not date and time
<asp:Label ID="lblDate" runat="server" Text='<%# Eval("PostDate") %>'></asp:Label>
this code show date and time together
add this
DataFormatString="{0:dd/MM/yyyy}"
<asp:Label ID="lblDate" runat="server" Text='<%# Eval("PostDate") %>' DataFormatString="{0:dd/MM/yyyy}" ></asp:Label>
change the Eval with format as below
Text='<%# Eval("PostDate", "{0:dd/MM/yyyy}") %>'