Validate textbox with date

Asked

Viewed 526 times

1

I have a textbox field that I need to type the date, I would like to know how I can do for when the user is typing, to validate the field, and if it is not correct, inform the user. What is the best way to do this validation? And how to do it?

  • 2

    I don’t know Sp, but while researching dates, found this., It has nothing to do with what I did, but by reading the comments I managed to solve my problem. Maybe I can help you.

  • It works, only it appears as Label, you know if it has any way to appear with icon ? Thank you.

  • It has jquery.maskedInput that masks the fields. You can set it to: 99/99/9999 and it will only allow numbers and only in this format. https://plugins.jquery.com/maskedinput/ And there are other plugins that do this too.

1 answer

2


A very simple way for you to do this validation is with Jquery Mask.

Download the plugin here https://igorescobar.github.io/jQuery-Mask-Plugin/ and in your code you will do the following:

<asp:TextBox runat="server" ID="TxtData" data-mask="00/00/0000" />

Don’t forget to initialize the plugin.

You can still create a class with your mask and use in other parts of the system in this way:

<script>
      $(function(){
          $(".data").mask("00/00/0000", {placeholder: "__/__/____"});
      })
</script>

You can use the placeholder as stated above to determine in the textbox how the entered value will be entered in the field.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.