简体   繁体   中英

How to masking date in textbox asp.net with javascript

I am Using textbox for input date user.
How to auto masking when user input value date with format mask "dd-MM-yyyy"

Thanks

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> 

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.

you can try following JScript:

$(document).ready(
  function() {
   $('#txtbx').click(
     function() {
         $("#txtbx").mask("999-99-9999");
        });
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM