jQuery UI: Date Picker

Date Picker

HTML

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/mint-choc/jquery-ui.css">
<script src="http://momentjs.com/downloads/moment.min.js"></script>
<p>Date:
    <input id="datepicker" type="text" value="12/12/2013">
</p>

JavaScript

$("#datepicker").datepicker();
var previousDate;

$("#datepicker").focus(function(){   
  previousDate= $(this).val(); ;
});
$("#datepicker").blur(function(){   
     var newDate = $(this).val();    
    if (!moment(newDate, 'DD/MM/YYYY', true).isValid()){         
        $(this).val(previousDate);      
        console.log("Error");
    }  
});