Search code examples
javascriptmasking

I can't add +591 before any number


I write this code for phone masking to add +591 before any phone number but it's not working. I can add +591 but 9 is not added. I don't know what I did wrong.

 <html>
<head>
    <style>
        input {
            font-family: monospace;
        }

        label {
            display: block;
        }

        div {
            margin: 0 0 1rem 0;
        }
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>
    <script>
        $(document).ready(function () {
            $(":input").inputmask();

            $("#phone").inputmask({
                "mask": "(+591) 999-9999"
            });
        });
    </script>
</head>

<body>
    <form action="">
       <div>
            <label for="phone">Phone</label>
            <!-- or set via JS -->
            <input id="phone" type="text" />
        </div>

    </form>
</body>

</html>

Solution

  • 9 is a symbol for inputmask library to know where placeholder are. Double escape it should work

    try this out

    $("#phone").inputmask({
                    "mask": "(+5\\91) 999-9999"
                });