Validation Issues with jQuery Mask

Asked

Viewed 202 times

1

I have this in my javascript file but I don’t know why it’s not working in my fields.

$(document).ready(function () {
    $("#number").mask('00000');
    $("#open-hour").mask('00:00');
    $("#close-hour").mask('00:00');
    $("#date-foundation").mask('00/00/0000');
    $("input[name=number]").mask("000000");
    $("#cnpj").mask('00.000.000/0000-00');



    $('#number-phone').blur(function () {
        if ($(this).val().length == 15) { // Celular com 9 dígitos + 2 dígitos DDD e 4 da máscara
            $('#number-phone').mask('(00) 00000-0009');
        } else {
            $('#number-phone').mask('(00) 0000-00009');
        }
    });

    showHours();
    showMenuPhones();
});

On my php page:

<script src="libs/assets/jquery-1.11.3.min.js"></script>
<script src="libs/js/jquery.mask.min.js"></script>

<div class="inputs-without-icon">
<?php
/* DATE FOUNDATION */
if ($Menu->getFundationDate() == NULL) {
    echo "<input type='text' name='dateFoundation' class='input-without-icon metade-without' placeholder='Data de Fundação' id='date-foundation' />";
} else {
    $dateF = date_create($Menu->getFundationDate());
    echo "<input type='text' name='dateFoundation' class='input-without-icon metade-without' placeholder='Data de Fundação' id='date-foundation' value='" . date_format($dateF, 'dmY') . "' />";
}

/* CNPJ */
if ($Menu->getCnpj() == NULL) {
    echo "<input type='text' name='cnpj' class='input-without-icon metade-without' placeholder='CNPJ (números)' id='cnpj'/>";
} else {
    echo "<input type='text' name='cnpj'     class='input-without-icon metade-without' placeholder='CNPJ (números)' id='cnpj' value='{$Menu->getCnpj()}'/>";
}
?>

</div>
  • Did you import the jQuery plugin on your page and the plugin script ? Check the browser error console for any errors. And if possible, post your HTML fields as well.

  • On my php page where my fields are I imported the jquery path.. <script src="libs/Assets/jquery-1.11.3.min. js"></script> <script src="libs/js/jquery.mask.min.js"></script>

  • Right. And you saw if there’s an error in the console ?

  • It’s not. It’s not even catching.

  • Put the HTML fields to see.

  • I posted for example the cnpj and the date.

  • Your page is on the air ? There is no mistake even ? Apparently there is nothing wrong.

  • Yeah, I can’t find the error.

  • Look, I ran a simple test on Jsfiddle and it worked. https://jsfiddle.net/0spxjok8/1/

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.