Limit input text that receives a date

Asked

Viewed 310 times

1

I’m having a problem where I have a text field where I get a date. However I need to limit the digits of days, months and year, for example 31/12/2019, I need the person can not type above 31 on the day, nor above 12 in the months or above the current year. It is currently possible to enter invalid dates such as 33/33/3333.

Note: the text field has a Mask for the date

<script>$(function(){
    $("#data").mask("99/99/9999",{placeholder:" "});
});
  • I believe that the best way to mecher with date is by using a Calendar plugin... I’ll send you an example link: https://jqueryui.com/datepicker/

2 answers

2

0

        Regex reg = new Regex(@"^((((0[1-9])|([1-2][0-9])|(3[0-1]))|([1-9]))\x2F(((0[1-9])|(1[0-2]))|([1-9]))\x2F(([0-9]{2})|(((19)|([2]([0]{1})))([0-9]{2}))))$");
        if (reg.IsMatch(textBox1.Text))
        {
            //Código caso seja 30/3/2019 (exemplo)
        }
        else
        {
            //Código caso seja 33/33/3333 (exemplo)
        }

Browser other questions tagged

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