Input mask pattern YYYY-dd-mm not working

Viewed 310

Dear sir i want to make pattern for input filed as YYYY-mm-dd but my code not working properly.Please help me to correct my code if possible i will be grateful to you.

<html>
<head>
<title>Enter a title, displayed at the top of the window.</title>
<script async src="//jsfiddle.net/fpoirier1/53nomjyb/embed/"></script>
<script>
(function($){
    
  
  $('input').val(new Date());
  
  $('input').inputmask("date",{
    placeholder: "yyyy-mm-dd", 
    separator: "-", 
    alias: "yyyy/mm/dd"
  });
  
  
})(jQuery)
</script>
</head>
<!-- The information between the BODY and /BODY tags is displayed.-->
<body>
<h1>Enter the main heading, usually the same as the title.</h1>

<input type="text">
<p>Be <b>bold</b> in stating your key points. Put them in a list: </p>
<ul>
<li>The first item in your list</li>
<li>The second item; <i>italicize</i> key words</li>
</ul>
<p>Improve your image by including an image. </p>
<p><img src="http://www.mygifs.com/CoverImage.gif" alt="A Great HTML Resource"></p>
<p>Add a link to your favorite <a href="https://www.dummies.com/">Web site</a>.
Break up your page with a horizontal rule or two. </p>
<hr>
<p>Finally, link to <a href="page2.html">another page</a> in your own Web site.</p>
<!-- And add a copyright notice.-->
<p>&#169; Wiley Publishing, 2011</p>
</body>
</html>
1 Answers

I spent hours on this trying to figure it out, then I realised that I could do it with the jQueryUI .datepicker() function.

var date = $('#date').datepicker({ dateFormat: 'yy-dd-mm' }).val();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<input id="date" type="text" placeholder="yyyy-dd-mm">

Related