Search code examples
jquerymaskfeature-detectionmaskedinput

jquery maskedinput. How to check availability of the mask


Can anyone help me with checking availability of the mask. I use this one:

if ($.isFunction($("#ID").mask)){
    var val = $("#ID").mask();
} else {
    var val = document.getElementById(ID).value;
}

but this condition is always TRUE. Don't matter written with:

$(document).ready(function(){
  $("#ID").mask("8 (999) 999-9999");
}

or not.


Solution

  • If you're trying to verify if the .mask() function is available, you should try checking $.fn.mask.

    If you're trying to verify whether an element has a mask, test if $("#element").data("rawMaskFn") is defined.