JavaScript How to validate date input to set it always 2 days of current day using javascript or jquery validate date input javascript,validate date input python,validate date

I have a date input

<input type="date" id="a" name="a" required />

Now i want its value to be set by user but it has to be set only after two days of current day, how do i do that using javascript or jquery?

What i already tried is -

<form id="f">
    <input type="date" id="d" />
    <input type="submit" value="submit" />
</form>    

$("#f").submit( function(e){
    var date=new Date();
    date = date.getDate()+2;
    if($("#d").val()<date){
        alert("fail");
        e.preventDefault();
    }else{
        alert("Success");
    }
} );
Answer:1

You need to create a date object and compare it to another date object set 2 days ahead.

See Fiddle: http://jsfiddle.net/g6aFz/

JS:

$("#f").submit( function(e){
    var $date = $("#a"),
        date = new Date($date.val()),
        date2 = new Date()

    date2.setDate(date2.getDate() + 2)

    if(date < date2){
        alert("fail");
        e.preventDefault();
    }else{
        alert("Success");
    }
} );
Answer:2

I'm using jQuery validator and jQuery 1.8.3. For some reason my form is submitted twice which causes errors. This is the code: someNameSpace.myValidateFunction = function(){ $('#myForm').validate(...

I'm using jQuery validator and jQuery 1.8.3. For some reason my form is submitted twice which causes errors. This is the code: someNameSpace.myValidateFunction = function(){ $('#myForm').validate(...

  1. jquery validation submit invalid form
  2. jquery validate form still submits

Our applications loading process is lengthy, so to provide the user with indication the app is functioning and merely loading, we want to provide a loading/initializing indicator. I tried using WL's ...

Our applications loading process is lengthy, so to provide the user with indication the app is functioning and merely loading, we want to provide a loading/initializing indicator. I tried using WL's ...

I have the following simple example, When the line extends outside the rectangle, I want to clip it. I already have the rectangle used as an outline, what is a simple way to the same rectangle as a ...

I have the following simple example, When the line extends outside the rectangle, I want to clip it. I already have the rectangle used as an outline, what is a simple way to the same rectangle as a ...

I'm trying to learn Knockout and I'm following these two tutorials: Tutorial 1 Better list example But after half a day of trying (and failing), I'm not able to add or remove an item. Here is my ...

I'm trying to learn Knockout and I'm following these two tutorials: Tutorial 1 Better list example But after half a day of trying (and failing), I'm not able to add or remove an item. Here is my ...

  1. remove items from list python
  2. remove items from array javascript
  3. remove items from list
  4. remove items from amazon history
  5. remove items from startup windows 10
  6. remove items from apple wallet
  7. remove items from launchpad
  8. remove items from dictionary python
  9. remove items from icloud
  10. remove items from kindle library
  11. remove items from list c#
  12. remove items from etsy cart
  13. remove items from menu bar mac
  14. remove items from dock
  15. remove items from google search
  16. remove items from google drive
  17. remove items from photos
  18. remove items from pictures
  19. remove items from buy again amazon
  20. remove items from quick access