Can't add mask to input

932 Views Asked by At

I can't add mask to input. I use jquery plugin for it https://github.com/RobinHerbots/Inputmask. My code:

<input id="iii">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="jquery.inputmask.min.js"></script>
<script >
  $(document).ready(function () {
    $('#iii').inputmask({
      mask: 'dd.mm.yyyy',
      placeholder: 'dd.mm.yyyy'
    })
  })
</script>

Or https://jsfiddle.net/3179or5n/

Plugin is initialized and placeholder appears in input, no errors, but I can't enter data in this input. What am I doing wrong? Any ideas

3

There are 3 best solutions below

0
On BEST ANSWER

Instead of mask you need to use these options:

alias: 'datetime',
inputFormat: 'dd.mm.yyyy',
inputmode: 'numeric'

For details see the doc

$('#iii').inputmask({
    alias: 'datetime',
    inputFormat: 'dd.mm.yyyy',
    inputmode: 'numeric',
    placeholder: 'dd.mm.yyyy'
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/RobinHerbots/[email protected]/dist/jquery.inputmask.js"></script>



<input id="iii">

0
On

I think what you're looking for is actually

$(document).ready(function () {
    $('#iii').inputmask({
      mask: '99.99.9999',
      placeholder: 'dd.mm.yyyy'
    })
})

Notice the mask is 99.99.9999 instead of mm.dd.yyyy

According to the documentation you should be using 9 for digits

0
On

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="./jquery.inputmask.min.js"></script>
</head>

<body>
    <input id="iii" type="text">
    <script>
        $(document).ready(function () {
            $('#iii').inputmask({
                "mask": "99.99.9999",
                "placeholder": "dd.mm.yyyy"
            });
        });
    </script>
</body>

</html>

I have checked and this is working for me