I am Using textbox for input date user.
How to auto masking when user input value date with format mask "dd-MM-yyyy"
Thanks
3 Answers
I'm not sure I understand your question, but you can use an ASP.NET CompareValidator to ensure the input is a valid date:
<asp:CompareValidator
id="cv_date" runat="server"
Type="Date"
Operator="DataTypeCheck"
ControlToValidate="tb_my_textbox"
ErrorMessage="Please enter a valid date.">
</asp:CompareValidator>
2 Comments
Brissles
No this will ensure the text that's entered is a valid date. Using this, you could then format the values entered in your codebehind using DateTime.ToString("dd-MM-yyyy");
Yusan Susandi
i'm using two language for my web. exist problem with this validator when switch to local language with other format date where i have format default for that for textbox is "dd/MM/yyyy". Tanks
You can't do that with the standard asp.net controls. You might try ajax control toollkit, which is a set of ajax controls. You can find out about it here: http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/MaskedEdit/MaskedEdit.aspx
Or you could build your own masking using javascript.
2 Comments
Yusan Susandi
I'm not using ajax, i'm use textbox wit jquery datetimepicker.
Nick Bray
You can write a custom function in jquery or javascript. Here is an example in another post:stackoverflow.com/questions/480979/…